diff --git a/.travis.yml b/.travis.yml index d3d1891..5fc86c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,7 @@ matrix: - php: 7.1 env: - COMPOSER_FLAGS='--prefer-lowest' - - php: 7.2 - -sudo: false + - php: 7.3 cache: directories: diff --git a/Form/Type/ResourceType.php b/Form/Type/ResourceType.php index 352919c..a01cfd4 100644 --- a/Form/Type/ResourceType.php +++ b/Form/Type/ResourceType.php @@ -17,17 +17,17 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class ResourceType extends AbstractType +final class ResourceType extends AbstractType { /** * @var MapBuilder */ - protected $mapBuilder; + private $mapBuilder; /** * @var string */ - protected $resourceClass; + private $resourceClass; public function __construct(MapBuilder $mapBuilder, string $resourceClass) { @@ -49,7 +49,7 @@ public function configureOptions(OptionsResolver $resolver) public function buildForm(FormBuilderInterface $builder, array $options) { if (false === $this->mapBuilder->hasResource($options['resource_key'])) { - throw new ResourceFormTypeException(sprintf('"%s" is not a valid resource key', $options['resource_key'])); + throw new ResourceFormTypeException("\"{$options['resource_key']}\" is not a valid resource key"); } $resource = $this->mapBuilder->getResource($options['resource_key']); diff --git a/Model/Resource.php b/Model/Resource.php index 9975d7e..5af9d4c 100644 --- a/Model/Resource.php +++ b/Model/Resource.php @@ -11,7 +11,9 @@ namespace FSi\Bundle\ResourceRepositoryBundle\Model; +use DateTime; use DateTimeImmutable; +use DateTimeInterface; class Resource implements ResourceValue { @@ -82,7 +84,7 @@ public function getTextValue() public function setDateValue($dateValue) { - $this->dateValue = $dateValue; + $this->dateValue = $this->toDateTimeImmutable($dateValue); } public function getDateValue() @@ -92,7 +94,7 @@ public function getDateValue() public function setDatetimeValue($datetimeValue) { - $this->datetimeValue = $datetimeValue; + $this->datetimeValue = $this->toDateTimeImmutable($datetimeValue); } public function getDatetimeValue() @@ -102,7 +104,7 @@ public function getDatetimeValue() public function setTimeValue($timeValue) { - $this->timeValue = $timeValue; + $this->timeValue = $this->toDateTimeImmutable($timeValue); } public function getTimeValue() @@ -139,4 +141,20 @@ public function getBoolValue() { return $this->boolValue; } + + /** + * Symfony date/time/datetime forms do not allow for default DateTimeImmutable + * value until version 4.2, so the values need to be casted manually. + * + * @param DateTimeInterface|null $value + * @return DateTimeImmutable|null + */ + private function toDateTimeImmutable(?DateTimeInterface $value): ?DateTimeImmutable + { + if (true === $value instanceof DateTime) { + $value = DateTimeImmutable::createFromMutable($value); + } + + return $value; + } } diff --git a/Model/ResourceValue.php b/Model/ResourceValue.php index 72dc831..8eaa7c5 100644 --- a/Model/ResourceValue.php +++ b/Model/ResourceValue.php @@ -11,7 +11,7 @@ namespace FSi\Bundle\ResourceRepositoryBundle\Model; -Interface ResourceValue +interface ResourceValue { /** * @param string $key diff --git a/Repository/MapBuilder.php b/Repository/MapBuilder.php index 61e7fa8..8d92218 100644 --- a/Repository/MapBuilder.php +++ b/Repository/MapBuilder.php @@ -95,7 +95,7 @@ protected function recursiveParseRawMap(?array $rawMap = [], ?string $parentPath { $map = []; - if (!is_array($rawMap)) { + if (false === is_array($rawMap)) { return $map; } @@ -133,7 +133,7 @@ protected function createResource(array $configuration, string $path): ResourceI { $type = $configuration['type']; - if (!array_key_exists($type, $this->resourceTypes)) { + if (false === array_key_exists($type, $this->resourceTypes)) { throw new ConfigurationException(sprintf( '"%s" is not a valid resource type. Try one from: %s', $type, @@ -183,7 +183,7 @@ protected function validateConfiguration(array $configuration, string $path): vo )); } - if (!array_key_exists('type', $configuration)) { + if (false === array_key_exists('type', $configuration)) { throw new ConfigurationException(sprintf( 'Missing "type" declaration in "%s" element configuration', $path diff --git a/Twig/ResourceRepositoryExtension.php b/Twig/ResourceRepositoryExtension.php index 30c1fdc..54ff9ea 100644 --- a/Twig/ResourceRepositoryExtension.php +++ b/Twig/ResourceRepositoryExtension.php @@ -15,23 +15,18 @@ use Twig\Extension\AbstractExtension; use Twig\TwigFunction; -class ResourceRepositoryExtension extends AbstractExtension +final class ResourceRepositoryExtension extends AbstractExtension { /** * @var Repository */ - protected $repository; + private $repository; public function __construct(Repository $repository) { $this->repository = $repository; } - public function getName() - { - return 'fsi_resource_repository'; - } - public function getFunctions() { return [ @@ -40,7 +35,7 @@ public function getFunctions() }), new TwigFunction('get_resource', function(string $key, $default = null) { $value = $this->repository->get($key); - return is_null($value) ? $default : $value; + return null !== $value ? $value : $default; }) ]; } diff --git a/composer.json b/composer.json index 81c5191..04afcd7 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "fsi/doctrine-extensions-bundle": "^1.0|^2.0", "fsi/form-extensions-bundle": "^2.0", "phpunit/phpunit": "^7.1", - "phpspec/phpspec": "^4.3", + "phpspec/phpspec": "^5.0", "phpspec/prophecy": "^1.7", "sebastian/exporter": "^3.1.0" },