Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use TYPO3\CMS\Core\Type\Enumeration instead of backed enums, as … #3

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Command/BatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Netlogix\Nxgooglelocations\Command;

use Netlogix\Nxgooglelocations\Domain\Model\Batch;
use Netlogix\Nxgooglelocations\Domain\Model\BatchState;
use Netlogix\Nxgooglelocations\Domain\Repository\BatchRepository;
use Netlogix\Nxgooglelocations\Enumerations\BatchState;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down
5 changes: 3 additions & 2 deletions Classes/Domain/Model/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use Exception;
use Netlogix\Nxgooglelocations\Enumerations\BatchState;
use Netlogix\Nxgooglelocations\Service\BackendUserImpersonator;
use Netlogix\Nxgooglelocations\Service\GeoCoder;
use Netlogix\Nxgooglelocations\Service\Importer;
Expand Down Expand Up @@ -42,7 +43,7 @@ class Batch extends AbstractEntity
#[TYPO3\Transient]
protected $callback;

protected BatchState $state = BatchState::NEW;
protected string $state = BatchState::NEW;

protected int $amount = 0;

Expand Down Expand Up @@ -108,7 +109,7 @@ public function cancel(): void
$this->setState(BatchState::CLOSED);
}

protected function setState(BatchState $state): void
protected function setState(string $state): void
{
$this->state = $state;
$this->emitStateChange();
Expand Down
14 changes: 0 additions & 14 deletions Classes/Domain/Model/BatchState.php

This file was deleted.

6 changes: 3 additions & 3 deletions Classes/Domain/Model/CodingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Netlogix\Nxgooglelocations\Domain\Model;

use Netlogix\Nxgooglelocations\Service\GeoCoder;
use Netlogix\Nxgooglelocations\Enumerations\CodingResultProbability;
use Netlogix\Nxgooglelocations\Service\GeoCoderStatus;
use TYPO3\CMS\Extbase\Property\Exception\InvalidSourceException;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
Expand All @@ -13,7 +13,7 @@
* An accessible data structure for Google geocoding results.
*
* @property array rawData
* @property GeoCoderStatus status
* @property string status
* @property string formattedAddress
* @property string addressResultFromGeocoding
* @property float latitude
Expand Down Expand Up @@ -48,7 +48,7 @@ public function __get($propertyName)
'longitude' => $this->longitude,
],
'probability' => ($this->status === GeoCoderStatus::ZERO_RESULTS)
? CodingResultProbability::ZERO_RESULTS->value
? CodingResultProbability::ZERO_RESULTS
: max(
$this->minProbability,
min(
Expand Down
12 changes: 0 additions & 12 deletions Classes/Domain/Model/CodingResultProbability.php

This file was deleted.

8 changes: 4 additions & 4 deletions Classes/Domain/Repository/BatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Netlogix\Nxgooglelocations\Domain\Repository;

use Netlogix\Nxgooglelocations\Domain\Model\BatchState;
use Netlogix\Nxgooglelocations\Enumerations\BatchState;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use Netlogix\Nxgooglelocations\Domain\Model\Batch;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -32,13 +32,13 @@ public function findOpenInFolder(int $storagePageId): QueryResultInterface

$query->setQuerySettings($querySettings);

$query->matching($query->logicalNot($query->equals('state', BatchState::CLOSED->value)));
$query->matching($query->logicalNot($query->equals('state', BatchState::CLOSED)));

return $query->execute();
}

public function findOneByState(BatchState $state): ?Batch
public function findOneByState(string $state): ?Batch
{
return $this->findOneBy(['state' => $state->value]);
return $this->findOneBy(['state' => $state]);
}
}
40 changes: 40 additions & 0 deletions Classes/Enumerations/BatchState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Netlogix\Nxgooglelocations\Enumerations;

use TYPO3\CMS\Core\Type\Enumeration;

final class BatchState extends Enumeration
{
/**
* @var string
*/
final public const __default = self::NEW;

/**
* @var string
*/
final public const NEW = 'new';

/**
* @var string
*/
final public const VALIDATING = 'validating';

/**
* @var string
*/
final public const GEOCODING = 'running';

/**
* @var string
*/
final public const PERSISTING = 'persisting';

/**
* @var string
*/
final public const CLOSED = 'closed';
}
25 changes: 25 additions & 0 deletions Classes/Enumerations/CodingResultProbability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Netlogix\Nxgooglelocations\Enumerations;

use TYPO3\CMS\Core\Type\Enumeration;

final class CodingResultProbability extends Enumeration
{
/**
* @var int
*/
final public const ZERO_RESULTS = -1;

/**
* @var int
*/
final public const MANUALLY_IMPORT = -255;

/**
* @var int
*/
final public const MANUALLY_EDITOR = -256;
}
20 changes: 20 additions & 0 deletions Classes/Enumerations/GeoCoderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Netlogix\Nxgooglelocations\Enumerations;

use TYPO3\CMS\Core\Type\Enumeration;

final class GeoCoderStatus extends Enumeration
{
/**
* @var string
*/
final public const OK = 'OK';

/**
* @var string
*/
final public const ZERO_RESULTS = 'ZERO_RESULTS';
}
5 changes: 3 additions & 2 deletions Classes/Service/GeoCoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Netlogix\Nxgooglelocations\Service;

use Exception;
use Netlogix\Nxgooglelocations\Domain\Model\CodingResultProbability;
use Netlogix\Nxgooglelocations\Domain\Model\CodingResult;
use Netlogix\Nxgooglelocations\Domain\Model\FieldMap;
use Netlogix\Nxgooglelocations\Enumerations\CodingResultProbability;
use Netlogix\Nxgooglelocations\Enumerations\GeoCoderStatus;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

Expand Down Expand Up @@ -52,7 +53,7 @@ public function needsToBeGeoCoded(array $tcaRecord): bool

public function setProbabilityToManually(array $tcaRecord): array
{
$tcaRecord[$this->fieldMap->probability] = CodingResultProbability::MANUALLY_IMPORT->value;
$tcaRecord[$this->fieldMap->probability] = CodingResultProbability::MANUALLY_IMPORT;

return $tcaRecord;
}
Expand Down
11 changes: 0 additions & 11 deletions Classes/Service/GeoCoderStatus.php

This file was deleted.