From 643b80d79f2decb4a97bea9cfaf58e2ce8e3f894 Mon Sep 17 00:00:00 2001 From: Denis Golubovskiy Date: Thu, 14 May 2020 09:43:15 +0300 Subject: [PATCH 1/3] Symfony 5 support --- .travis.yml | 2 ++ DependencyInjection/Configuration.php | 7 +++++-- Tests/EventListener/JmsSerializeListenerTest.php | 4 ++-- composer.json | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad83f6a..e60c774 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ sudo: false php: - 7.1 + - 7.2 + - 7.4 before_script: - composer self-update diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 516e1be..1260a22 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -26,8 +26,11 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder(): NodeParentInterface { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('bukashk0zzz_liip_imagine_serialization'); + $treeBuilder = new TreeBuilder('bukashk0zzz_liip_imagine_serialization'); + + $rootNode = \method_exists($treeBuilder, 'getRootNode') + ? $treeBuilder->getRootNode() + : $treeBuilder->root('bukashk0zzz_liip_imagine_serialization'); $rootNode ->children() diff --git a/Tests/EventListener/JmsSerializeListenerTest.php b/Tests/EventListener/JmsSerializeListenerTest.php index 08e96e7..7993575 100644 --- a/Tests/EventListener/JmsSerializeListenerTest.php +++ b/Tests/EventListener/JmsSerializeListenerTest.php @@ -524,8 +524,8 @@ protected function generateVichStorage(): void $this->vichStorage = $this->getMockBuilder(FileSystemStorage::class) ->disableOriginalConstructor() ->getMock(); - $this->vichStorage->expects(static::any()) + $this->vichStorage ->method('resolveUri') - ->will(static::returnValue('/uploads/photo.jpg')); + ->willReturn('/uploads/photo.jpg'); } } diff --git a/composer.json b/composer.json index 6843b2c..cdbcce1 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,11 @@ }, "require": { "php": ">=7.1.0", - "symfony/dependency-injection": "^3.3|^4.0", - "symfony/yaml": "^3.3|^4.0", + "symfony/dependency-injection": "^3.3|^4.0|^5.0", + "symfony/yaml": "^3.3|^4.0|^5.0", "doctrine/orm": "^2.5", - "jms/serializer-bundle": "^2.0", - "liip/imagine-bundle": "^1.8", + "jms/serializer-bundle": "^2.0|^3.0", + "liip/imagine-bundle": "^1.8|2.3", "vich/uploader-bundle": "^1.5" }, "require-dev": { From d41e9faf8b49e0484fa60f9d83767b2194ff0c40 Mon Sep 17 00:00:00 2001 From: Denis Golubovskiy Date: Thu, 14 May 2020 09:47:36 +0300 Subject: [PATCH 2/3] Update php CS --- .travis.yml | 2 +- Annotation/LiipImagineSerializableField.php | 24 ------- DependencyInjection/Configuration.php | 2 - Event/UrlNormalizerEvent.php | 11 --- .../JmsSerializeListenerAbstract.php | 31 +------- Normalizer/UrlNormalizerInterface.php | 5 -- .../LiipImagineSerializableFieldTest.php | 1 + .../JmsSerializeContextGenerator.php | 2 - .../JmsSerializeEventsManager.php | 15 +--- .../JmsSerializeListenerTest.php | 13 +--- ...ukashk0zzzSerializationEventSubscriber.php | 6 -- Tests/Fixtures/User.php | 35 +--------- Tests/Fixtures/UserPictures.php | 58 +-------------- composer.json | 2 - ruleset.xml | 70 ------------------- 15 files changed, 13 insertions(+), 264 deletions(-) delete mode 100644 ruleset.xml diff --git a/.travis.yml b/.travis.yml index e60c774..c861b76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_script: - composer install --dev --prefer-dist --no-interaction script: - - ./vendor/bin/phpcs ./ -p --standard=./ruleset.xml + - ./vendor/bin/php-cs-fixer fix --config=.php_cs -vvv --dry-run - ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml after_success: diff --git a/Annotation/LiipImagineSerializableField.php b/Annotation/LiipImagineSerializableField.php index e43efed..2d9e40e 100644 --- a/Annotation/LiipImagineSerializableField.php +++ b/Annotation/LiipImagineSerializableField.php @@ -78,8 +78,6 @@ public function getFilter() /** * @param string|string[] $filter - * - * @return LiipImagineSerializableField */ public function setFilter($filter): LiipImagineSerializableField { @@ -88,19 +86,11 @@ public function setFilter($filter): LiipImagineSerializableField return $this; } - /** - * @return string|null - */ public function getVichUploaderField(): ?string { return $this->vichUploaderField; } - /** - * @param string $vichUploaderField - * - * @return LiipImagineSerializableField - */ public function setVichUploaderField(string $vichUploaderField): LiipImagineSerializableField { $this->vichUploaderField = $vichUploaderField; @@ -108,19 +98,11 @@ public function setVichUploaderField(string $vichUploaderField): LiipImagineSeri return $this; } - /** - * @return string|null - */ public function getVirtualField(): ?string { return $this->virtualField; } - /** - * @param string $virtualField - * - * @return LiipImagineSerializableField - */ public function setVirtualField(string $virtualField): LiipImagineSerializableField { $this->virtualField = $virtualField; @@ -128,12 +110,6 @@ public function setVirtualField(string $virtualField): LiipImagineSerializableFi return $this; } - /** - * @param string $optionName - * @param bool $canBeArray - * - * @return bool - */ private function checkOption(string $optionName, bool $canBeArray): bool { if (\array_key_exists($optionName, $this->options)) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1260a22..78a17db 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -21,8 +21,6 @@ class Configuration implements ConfigurationInterface { /** * Generates the configuration tree. - * - * @return \Symfony\Component\Config\Definition\Builder\NodeParentInterface */ public function getConfigTreeBuilder(): NodeParentInterface { diff --git a/Event/UrlNormalizerEvent.php b/Event/UrlNormalizerEvent.php index e02dd6d..12ec1a2 100644 --- a/Event/UrlNormalizerEvent.php +++ b/Event/UrlNormalizerEvent.php @@ -17,27 +17,16 @@ class UrlNormalizerEvent extends Event */ protected $url; - /** - * @param string $url - */ public function __construct(string $url) { $this->url = $url; } - /** - * @return string - */ public function getUrl(): string { return $this->url; } - /** - * @param string $url - * - * @return UrlNormalizerEvent - */ public function setUrl(string $url): UrlNormalizerEvent { $this->url = $url; diff --git a/EventListener/JmsSerializeListenerAbstract.php b/EventListener/JmsSerializeListenerAbstract.php index dc31215..a4165b0 100644 --- a/EventListener/JmsSerializeListenerAbstract.php +++ b/EventListener/JmsSerializeListenerAbstract.php @@ -59,12 +59,7 @@ class JmsSerializeListenerAbstract /** * JmsSerializeListenerAbstract constructor. * - * @param RequestContext $requestContext - * @param CachedReader $annotationReader - * @param CacheManager $cacheManager - * @param StorageInterface $vichStorage - * @param EventDispatcherInterface $eventDispatcher - * @param mixed[] $config + * @param mixed[] $config */ public function __construct( RequestContext $requestContext, @@ -101,9 +96,8 @@ protected function getObject(ObjectEvent $event) } /** - * @param LiipImagineSerializableField $liipAnnotation - * @param mixed $object Serialized object - * @param string $value Value of field + * @param mixed $object Serialized object + * @param string $value Value of field * * @return mixed[]|string */ @@ -162,11 +156,6 @@ protected function getHostUrl(): string /** * Normalize url if needed - * - * @param string $url - * @param string $normalizer - * - * @return string */ protected function normalizeUrl(string $url, string $normalizer): string { @@ -185,10 +174,6 @@ protected function normalizeUrl(string $url, string $normalizer): string /** * If config demands, it will remove host and scheme (protocol) from passed url - * - * @param string $url - * - * @return string */ private function prepareFilteredUrl(string $url): string { @@ -201,10 +186,6 @@ private function prepareFilteredUrl(string $url): string /** * Removes host and scheme (protocol) from passed url - * - * @param string $url - * - * @return string */ private function stripHostFromUrl(string $url): string { @@ -216,12 +197,6 @@ private function stripHostFromUrl(string $url): string throw new \InvalidArgumentException('Can\'t strip host from url, because can\'t parse url.'); } - /** - * @param string $type - * @param string $url - * - * @return string - */ private function addPreNormalizeUrlEvent(string $type, string $url): string { /** @var UrlNormalizerEvent $event */ diff --git a/Normalizer/UrlNormalizerInterface.php b/Normalizer/UrlNormalizerInterface.php index 36f3c72..162ed70 100644 --- a/Normalizer/UrlNormalizerInterface.php +++ b/Normalizer/UrlNormalizerInterface.php @@ -10,10 +10,5 @@ interface UrlNormalizerInterface public const TYPE_ORIGIN = 'originUrlNormalizer'; public const TYPE_FILTERED = 'filteredUrlNormalizer'; - /** - * @param string|null $url - * - * @return string - */ public function normalize(?string $url): string; } diff --git a/Tests/Annotation/LiipImagineSerializableFieldTest.php b/Tests/Annotation/LiipImagineSerializableFieldTest.php index c7fa8f7..512b16b 100644 --- a/Tests/Annotation/LiipImagineSerializableFieldTest.php +++ b/Tests/Annotation/LiipImagineSerializableFieldTest.php @@ -1,4 +1,5 @@ requestContext = $this->getMockBuilder(RequestContext::class) @@ -455,9 +451,6 @@ protected function generateRequestContext(bool $https = false, bool $port = fals /** * Prepare mock of Liip cache manager - * - * @param string $urlPrefix - * @param bool $isStored */ protected function generateCacheManager(string $urlPrefix = 'http://example.com:8800/', bool $isStored = true): void { @@ -465,7 +458,7 @@ protected function generateCacheManager(string $urlPrefix = 'http://example.com: $resolver ->expects(static::any()) ->method('isStored') - ->will(static::returnValue($isStored)) + ->willReturn($isStored) ; $resolver ->expects(static::any()) @@ -485,11 +478,11 @@ protected function generateCacheManager(string $urlPrefix = 'http://example.com: $config = $this->getMockBuilder(FilterConfiguration::class)->getMock(); $config->expects(static::any()) ->method('get') - ->will(static::returnValue([ + ->willReturn([ 'size' => [180, 180], 'mode' => 'outbound', 'cache' => null, - ])) + ]) ; $router = $this->getMockBuilder(RouterInterface::class)->getMock(); diff --git a/Tests/EventSubscriber/Bukashk0zzzSerializationEventSubscriber.php b/Tests/EventSubscriber/Bukashk0zzzSerializationEventSubscriber.php index c2963e1..88f1b11 100644 --- a/Tests/EventSubscriber/Bukashk0zzzSerializationEventSubscriber.php +++ b/Tests/EventSubscriber/Bukashk0zzzSerializationEventSubscriber.php @@ -33,17 +33,11 @@ public static function getSubscribedEvents(): array ]; } - /** - * @param UrlNormalizerEvent $event - */ public function normalizeOrigin(UrlNormalizerEvent $event): void { $event->setUrl(\str_replace('photo', 'newPhoto', $event->getUrl())); } - /** - * @param UrlNormalizerEvent $event - */ public function normalizeFiltered(UrlNormalizerEvent $event): void { $event->setUrl(\str_replace('example.com', 'img.example.com', $event->getUrl())); diff --git a/Tests/Fixtures/User.php b/Tests/Fixtures/User.php index c0ddad8..9ce2b15 100644 --- a/Tests/Fixtures/User.php +++ b/Tests/Fixtures/User.php @@ -91,6 +91,7 @@ class User /** * User constructor. + * * @param null $photoName */ public function __construct($photoName = null) @@ -106,8 +107,6 @@ public function __construct($photoName = null) /** * To string - * - * @return string */ public function __toString(): string { @@ -128,8 +127,6 @@ public function getPhotoName(): string * Set photo name * * @param string $photoName Photo name - * - * @return User */ public function setPhotoName(string $photoName): User { @@ -152,8 +149,6 @@ public function getPhotoFile(): File * Set photo file * * @param File $photoFile Photo file - * - * @return User */ public function setPhotoFile(File $photoFile): User { @@ -164,10 +159,6 @@ public function setPhotoFile(File $photoFile): User /** * Add userPictures - * - * @param UserPictures $userPictures - * - * @return User */ public function addUserPictures(UserPictures $userPictures): User { @@ -178,8 +169,6 @@ public function addUserPictures(UserPictures $userPictures): User /** * Get userPictures - * - * @return \Doctrine\Common\Collections\Collection */ public function getUserPictures(): Collection { @@ -188,10 +177,6 @@ public function getUserPictures(): Collection /** * Add userPhotos - * - * @param UserPhotos $userPhotos - * - * @return User */ public function addUserPhotos(UserPhotos $userPhotos): User { @@ -202,27 +187,17 @@ public function addUserPhotos(UserPhotos $userPhotos): User /** * Get userPhotos - * - * @return \Doctrine\Common\Collections\Collection */ public function getUserPhotos(): Collection { return $this->userPhotos; } - /** - * @return string - */ public function getCoverUrl(): string { return $this->coverUrl; } - /** - * @param string $coverUrl - * - * @return User - */ public function setCoverUrl(string $coverUrl): User { $this->coverUrl = $coverUrl; @@ -230,19 +205,11 @@ public function setCoverUrl(string $coverUrl): User return $this; } - /** - * @return string - */ public function getImageUrl(): string { return $this->imageUrl; } - /** - * @param string $imageUrl - * - * @return User - */ public function setImageUrl(string $imageUrl): User { $this->imageUrl = $imageUrl; diff --git a/Tests/Fixtures/UserPictures.php b/Tests/Fixtures/UserPictures.php index 7a9e03a..bcd5605 100644 --- a/Tests/Fixtures/UserPictures.php +++ b/Tests/Fixtures/UserPictures.php @@ -1,4 +1,5 @@ user; } - /** - * @return string - */ public function getCoverUrl(): string { return $this->coverUrl; } - /** - * @param string $coverUrl - * - * @return UserPictures - */ public function setCoverUrl(string $coverUrl): UserPictures { $this->coverUrl = $coverUrl; @@ -197,19 +161,11 @@ public function setCoverUrl(string $coverUrl): UserPictures return $this; } - /** - * @return string - */ public function getImageUrl(): string { return $this->imageUrl; } - /** - * @param string $imageUrl - * - * @return UserPictures - */ public function setImageUrl(string $imageUrl): UserPictures { $this->imageUrl = $imageUrl; @@ -227,8 +183,6 @@ public function getPhotoName() /** * @param mixed $photoName - * - * @return UserPictures */ public function setPhotoName($photoName): UserPictures { @@ -237,19 +191,11 @@ public function setPhotoName($photoName): UserPictures return $this; } - /** - * @return File - */ public function getPhotoFile(): File { return $this->photoFile; } - /** - * @param File $photoFile - * - * @return UserPictures - */ public function setPhotoFile(File $photoFile): UserPictures { $this->photoFile = $photoFile; diff --git a/composer.json b/composer.json index cdbcce1..8e252ad 100644 --- a/composer.json +++ b/composer.json @@ -26,8 +26,6 @@ "vich/uploader-bundle": "^1.5" }, "require-dev": { - "escapestudios/symfony2-coding-standard": "^3.0", - "slevomat/coding-standard": "^4.0", "friendsofphp/php-cs-fixer": "^2.8", "phpunit/phpunit": "^6.4" }, diff --git a/ruleset.xml b/ruleset.xml deleted file mode 100644 index f774ea0..0000000 --- a/ruleset.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - Bukashk0zzz coding standard. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - 0 - - - - - - - vendor/ - - ./ - From 61902d0574a41232edde1d18906903c0ddba9a68 Mon Sep 17 00:00:00 2001 From: Denis Golubovskiy Date: Thu, 14 May 2020 10:12:45 +0300 Subject: [PATCH 3/3] Symfony 5 fixes --- .travis.yml | 1 - Event/UrlNormalizerEvent.php | 2 +- EventListener/JmsSerializeListenerAbstract.php | 4 ++-- .../EventListener/JmsSerializeContextGenerator.php | 13 +++---------- composer.json | 10 +++++----- phpunit.xml.dist | 5 +++-- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index c861b76..8bbbb86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: php sudo: false php: - - 7.1 - 7.2 - 7.4 diff --git a/Event/UrlNormalizerEvent.php b/Event/UrlNormalizerEvent.php index 12ec1a2..7682b6c 100644 --- a/Event/UrlNormalizerEvent.php +++ b/Event/UrlNormalizerEvent.php @@ -2,7 +2,7 @@ namespace Bukashk0zzz\LiipImagineSerializationBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * UrlNormalizerEvent diff --git a/EventListener/JmsSerializeListenerAbstract.php b/EventListener/JmsSerializeListenerAbstract.php index a4165b0..7e961ce 100644 --- a/EventListener/JmsSerializeListenerAbstract.php +++ b/EventListener/JmsSerializeListenerAbstract.php @@ -201,10 +201,10 @@ private function addPreNormalizeUrlEvent(string $type, string $url): string { /** @var UrlNormalizerEvent $event */ $event = $this->eventDispatcher->dispatch( + new UrlNormalizerEvent($url), $type === UrlNormalizerInterface::TYPE_ORIGIN ? UrlNormalizerEvent::ORIGIN - : UrlNormalizerEvent::FILTERED, - new UrlNormalizerEvent($url) + : UrlNormalizerEvent::FILTERED ); return $event->getUrl(); diff --git a/Tests/EventListener/JmsSerializeContextGenerator.php b/Tests/EventListener/JmsSerializeContextGenerator.php index 1846573..e2db1fa 100644 --- a/Tests/EventListener/JmsSerializeContextGenerator.php +++ b/Tests/EventListener/JmsSerializeContextGenerator.php @@ -11,9 +11,8 @@ namespace Bukashk0zzz\LiipImagineSerializationBundle\Tests\EventListener; use Doctrine\Common\Annotations\AnnotationReader; -use JMS\Serializer\Construction\UnserializeObjectConstructor; +use JMS\Serializer\Accessor\DefaultAccessorStrategy; use JMS\Serializer\DeserializationContext; -use JMS\Serializer\EventDispatcher\EventDispatcher; use JMS\Serializer\GraphNavigator; use JMS\Serializer\Handler\HandlerRegistry; use JMS\Serializer\JsonSerializationVisitor; @@ -22,21 +21,15 @@ use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; use Metadata\MetadataFactory; -/** - * JmsSerializeContextGenerator - */ class JmsSerializeContextGenerator { - /** - * Generate JMS context - */ public function generateContext(): DeserializationContext { $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); $context = DeserializationContext::create(); - $factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader())); - $context->initialize('json', new JsonSerializationVisitor($namingStrategy), new GraphNavigator($factory, new HandlerRegistry(), new UnserializeObjectConstructor(), new EventDispatcher()), $factory); + $factory = new MetadataFactory(new AnnotationDriver(new AnnotationReader(), $namingStrategy)); + $context->initialize('json', new JsonSerializationVisitor(), new GraphNavigator\SerializationGraphNavigator($factory, new HandlerRegistry(), new DefaultAccessorStrategy()), $factory); return $context; } diff --git a/composer.json b/composer.json index 8e252ad..c26073d 100644 --- a/composer.json +++ b/composer.json @@ -17,17 +17,17 @@ "issues": "https://github.com/bukashk0zzz/LiipImagineSerializationBundle/issues" }, "require": { - "php": ">=7.1.0", - "symfony/dependency-injection": "^3.3|^4.0|^5.0", - "symfony/yaml": "^3.3|^4.0|^5.0", + "php": ">=7.2.0", + "symfony/dependency-injection": "^4.0|^5.0", + "symfony/yaml": "^4.0|^5.0", "doctrine/orm": "^2.5", - "jms/serializer-bundle": "^2.0|^3.0", + "jms/serializer-bundle": "^3.0", "liip/imagine-bundle": "^1.8|2.3", "vich/uploader-bundle": "^1.5" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.8", - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^7.2" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5dadb78..63f935c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,8 @@ -