diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b57d380e83..a9fcfc7997 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3408,60 +3408,6 @@ parameters: count: 1 path: src/bundle/Core/IbexaCoreBundle.php - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\AliasCleaner\:\:removeAliases\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/AliasCleaner.php - - - - message: '#^Parameter \#1 \$image of method Ibexa\\Bundle\\Core\\Imagine\\AliasGenerator\:\:applyFilter\(\) expects Liip\\ImagineBundle\\Binary\\BinaryInterface, Liip\\ImagineBundle\\Binary\\BinaryInterface\|string given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/AliasGenerator.php - - - - message: '#^Parameter \#1 \$mimeType of method Symfony\\Component\\Mime\\MimeTypesInterface\:\:getExtensions\(\) expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/BinaryLoader.php - - - - message: '#^Parameter \#2 \$mimeType of class Liip\\ImagineBundle\\Model\\Binary constructor expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/BinaryLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:getTagsForVariation\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:getVariation\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:setSiteAccess\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\Cache\\AliasGeneratorDecorator\:\:\$siteAccess \(Ibexa\\Core\\MVC\\Symfony\\SiteAccess\) does not accept Ibexa\\Core\\MVC\\Symfony\\SiteAccess\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php - - - - message: '#^Property Ibexa\\Core\\MVC\\Symfony\\SiteAccess\:\:\$name \(string\) on left side of \?\? is not nullable\.$#' - identifier: nullCoalesce.property - count: 2 - path: src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\Resolver\\RelativeResolver\:\:rewriteUrl\(\) has parameter \$url with no type specified\.$#' identifier: missingType.parameter @@ -3474,276 +3420,12 @@ parameters: count: 1 path: src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Cache\\ResolverFactory\:\:createCacheResolver\(\) should return Liip\\ImagineBundle\\Imagine\\Cache\\Resolver\\ResolverInterface but returns object\.$#' - identifier: return.type - count: 1 - path: src/bundle/Core/Imagine/Cache/ResolverFactory.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:__construct\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:getOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:setOption\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:setOptions\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:setOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\Filter\\AbstractFilter\:\:\$options type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/AbstractFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:all\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:get\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:getVariationFilters\(\) has parameter \$configuredVariations with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:getVariationFilters\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:getVariationPostProcessors\(\) has parameter \$configuredVariations with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:getVariationPostProcessors\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterConfiguration\:\:setConfigResolver\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterConfiguration.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterInterface\:\:getOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterInterface.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterInterface\:\:setOption\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterInterface.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterInterface\:\:setOptions\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterInterface.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\FilterInterface\:\:setOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/FilterInterface.php - - - - message: '#^Call to an undefined method Imagine\\Image\\ImageInterface\:\:getGmagick\(\)\.$#' - identifier: method.notFound - count: 1 - path: src/bundle/Core/Imagine/Filter/Gmagick/ReduceNoiseFilter.php - - - - message: '#^Call to an undefined method Imagine\\Image\\ImageInterface\:\:getGmagick\(\)\.$#' - identifier: method.notFound - count: 1 - path: src/bundle/Core/Imagine/Filter/Gmagick/SwirlFilter.php - - - - message: '#^Call to an undefined method Imagine\\Image\\ImageInterface\:\:getImagick\(\)\.$#' - identifier: method.notFound - count: 1 - path: src/bundle/Core/Imagine/Filter/Imagick/ReduceNoiseFilter.php - - - - message: '#^Call to an undefined method Imagine\\Image\\ImageInterface\:\:getImagick\(\)\.$#' - identifier: method.notFound - count: 1 - path: src/bundle/Core/Imagine/Filter/Imagick/SwirlFilter.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/BorderFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\CropFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/CropFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\FilterLoaderWrapped\:\:setInnerLoader\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/FilterLoaderWrapped.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\GrayscaleFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ReduceNoiseFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleDownOnlyFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleExactFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightDownOnlyFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScalePercentFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthDownOnlyFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\Filter\\Loader\\SwirlFilterLoader\:\:load\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoader.php - - message: '#^Parameter \#2 \$data of function fwrite expects string, string\|false given\.$#' identifier: argument.type count: 1 path: src/bundle/Core/Imagine/IORepositoryResolver.php - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGenerator\:\:setPlaceholderProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGenerator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGenerator\:\:setPlaceholderProvider\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGenerator.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGenerator\:\:\$placeholderOptions type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGenerator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorConfigurator\:\:__construct\(\) has parameter \$providersConfig with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorConfigurator\:\:configure\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorConfigurator\:\:\$providersConfig type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\:\:getPlaceholder\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProvider\:\:getPlaceholder\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProvider\:\:resolveOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -3756,78 +3438,12 @@ parameters: count: 1 path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - message: '#^Parameter \#1 \$width of class Imagine\\Image\\Box constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - - message: '#^Parameter \#1 \$x of class Imagine\\Image\\Point constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 2 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - - message: '#^Parameter \#2 \$font of method Imagine\\Draw\\DrawerInterface\:\:text\(\) expects Imagine\\Image\\AbstractFont, Imagine\\Image\\FontInterface given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - - message: '#^Parameter \#2 \$height of class Imagine\\Image\\Box constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - - message: '#^Parameter \#2 \$y of class Imagine\\Image\\Point constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 2 - path: src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\\RemoteProvider\:\:getPlaceholder\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\\RemoteProvider\:\:resolveOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\\RemoteProvider\:\:resolveOptions\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php - - - message: '#^Cannot access offset string on Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: src/bundle/Core/Imagine/PlaceholderProviderRegistry.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistry\:\:__construct\(\) has parameter \$providers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProviderRegistry.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistry\:\:addProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProviderRegistry.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistry\:\:\$providers \(Ibexa\\Bundle\\Core\\Imagine\\PlaceholderProvider\) does not accept array\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/Core/Imagine/PlaceholderProviderRegistry.php - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\Variation\\ImagineAwareAliasGenerator\:\:\$configResolver is unused\.$#' identifier: property.unused @@ -3846,60 +3462,6 @@ parameters: count: 1 path: src/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGenerator.php - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\IOVariationPurger\:\:setLogger\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\IOVariationPurger\:\:\$logger \(Psr\\Log\\LoggerInterface\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php - - - - message: '#^Interface Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileList extends generic interface Iterator but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/ImageFileList.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileRowReader\:\:init\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurger\:\:setLogger\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurger\:\:\$imageFileList \(Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileList\) does not accept Iterator\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php - - - - message: '#^Property Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurger\:\:\$logger \(Psr\\Log\\LoggerInterface\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileList\:\:count\(\) should return int\<0, max\> but returns int\.$#' - identifier: return.type - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileList.php - - - - message: '#^Method Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileRowReader\:\:init\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileRowReader.php - - message: '#^Method Ibexa\\Bundle\\Core\\Matcher\\ServiceAwareMatcherFactory\:\:__construct\(\) has parameter \$matchConfig with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -4158,24 +3720,6 @@ parameters: count: 1 path: src/bundle/Debug/Collector/PersistenceCacheCollector.php - - - message: '#^Method Ibexa\\Bundle\\IO\\ApiLoader\\HandlerRegistry\:\:setHandlersMap\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/IO/ApiLoader/HandlerRegistry.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\ApiLoader\\HandlerRegistry\:\:setHandlersMap\(\) has parameter \$handlersMap with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/IO/ApiLoader/HandlerRegistry.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\ApiLoader\\HandlerRegistry\:\:\$handlersMap type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/IO/ApiLoader/HandlerRegistry.php - - message: '#^Assert references unknown \$request\-\>headers\-\.$#' identifier: assert.unknownExpr @@ -4195,688 +3739,292 @@ parameters: path: src/bundle/IO/BinaryStreamResponse.php - - message: '#^Call to an undefined method Symfony\\Component\\Console\\Helper\\HelperInterface\:\:ask\(\)\.$#' + message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:children\(\)\.$#' identifier: method.notFound count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/IO/DependencyInjection/Configuration.php - - message: '#^Method Ibexa\\Bundle\\IO\\Command\\MigrateFilesCommand\:\:__construct\(\) has parameter \$configuredBinarydataHandlers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Parameter \#3 \$length of function substr expects int\|null, int\<0, max\>\|false given\.$#' + identifier: argument.type count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php - - message: '#^Method Ibexa\\Bundle\\IO\\Command\\MigrateFilesCommand\:\:__construct\(\) has parameter \$configuredMetadataHandlers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Bundle\\LegacySearchEngine\\ApiLoader\\ConnectionFactory\:\:getConnection\(\) should return Doctrine\\DBAL\\Connection but returns object\.$#' + identifier: return.type count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/LegacySearchEngine/ApiLoader/ConnectionFactory.php - - message: '#^Method Ibexa\\Bundle\\IO\\Command\\MigrateFilesCommand\:\:migrateFiles\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Parameter \#1 \$array of function array_keys expects array, array\|bool\|float\|int\|string\|null given\.$#' + identifier: argument.type count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/LegacySearchEngine/ApiLoader/ConnectionFactory.php - - message: '#^Method Ibexa\\Bundle\\IO\\Command\\MigrateFilesCommand\:\:outputConfiguredHandlers\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Bundle\\LegacySearchEngine\\IbexaLegacySearchEngineBundle\:\:getContainerExtension\(\) should return Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|null but returns Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|false\.$#' + identifier: return.type count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php - - message: '#^Parameter \#2 \$max of class Symfony\\Component\\Console\\Helper\\ProgressBar constructor expects int, int\|null given\.$#' - identifier: argument.type + message: '#^Call to an undefined method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:setOutput\(\)\.$#' + identifier: method.notFound count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php - - - - message: '#^Parameter \#3 \$toMetadataHandlerIdentifier of method Ibexa\\Bundle\\IO\\Migration\\MigrationHandlerInterface\:\:setIODataHandlersByIdentifiers\(\) expects string, int\|string given\.$#' - identifier: argument.type - count: 2 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Parameter \#4 \$toBinarydataHandlerIdentifier of method Ibexa\\Bundle\\IO\\Migration\\MigrationHandlerInterface\:\:setIODataHandlersByIdentifiers\(\) expects string, int\|string given\.$#' - identifier: argument.type - count: 2 - path: src/bundle/IO/Command/MigrateFilesCommand.php + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:__construct\(\) has parameter \$installers with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Strict comparison using \=\=\= between \(float\|int\) and null will always evaluate to false\.$#' - identifier: identical.alwaysFalse + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:cacheClear\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/Command/MigrateFilesCommand.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:__construct\(\) has parameter \$binarydataHandlerFactories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:checkPermissions\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:__construct\(\) has parameter \$metadataHandlerFactories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:executeCommand\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:getFactory\(\) has parameter \$factories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:getInstaller\(\) has parameter \$type with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:processHandlers\(\) has parameter \$configuredHandlers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:getInstaller\(\) should return Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer but returns false\.$#' + identifier: return.type count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:processHandlers\(\) has parameter \$factories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:indexData\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - message: '#^Parameter \#3 \$configuredHandlers of method Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:processHandlers\(\) expects array, array\|bool\|float\|int\|string\|null given\.$#' - identifier: argument.type - count: 2 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Event\\Subscriber\\BuildSchemaSubscriber\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: src/bundle/RepositoryInstaller/Event/Subscriber/BuildSchemaSubscriber.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:\$binarydataHandlerFactories \(ArrayObject&iterable\\) does not accept ArrayObject\|null\.$#' - identifier: assign.propertyType + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importBinaries\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:\$binarydataHandlerFactories with generic class ArrayObject does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importData\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:\$metadataHandlerFactories \(ArrayObject&iterable\\) does not accept ArrayObject\|null\.$#' - identifier: assign.propertyType + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importSchema\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPass\:\:\$metadataHandlerFactories with generic class ArrayObject does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:copyConfigurationFile\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:children\(\)\.$#' - identifier: method.notFound + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:getKernelSQLFileForDBMS\(\) should return string but returns string\|false\.$#' + identifier: return.type count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:addHandlersSection\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:runQueriesFromFile\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:addHandlersSection\(\) has parameter \$factories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:runQueriesFromFile\(\) has parameter \$file with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:setBinarydataHandlerFactories\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:setOutput\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:setBinarydataHandlerFactories\(\) has parameter \$factories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Parameter \#1 \$array of function array_filter expects array, list\\|false given\.$#' + identifier: argument.type count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:setMetadataHandlerFactories\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Parameter \#2 \$subject of function preg_split expects string, string\|false given\.$#' + identifier: argument.type count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:setMetadataHandlerFactories\(\) has parameter \$factories with generic class ArrayObject but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importBinaries\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/Installer.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:\$binarydataHandlerFactories \(ArrayObject&iterable\\) does not accept default value of type array\.$#' - identifier: property.defaultValue + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importData\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/Installer.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:\$binarydataHandlerFactories with generic class ArrayObject does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importSchema\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/bundle/RepositoryInstaller/Installer/Installer.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:\$metadataHandlerFactories \(ArrayObject&iterable\\) does not accept default value of type array\.$#' - identifier: property.defaultValue + message: '#^Template type TValue is declared as covariant, but occurs in invariant position in property Ibexa\\Contracts\\Core\\Collection\\AbstractInMemoryCollection\:\:\$items\.$#' + identifier: generics.variance count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/contracts/Collection/AbstractInMemoryCollection.php - - message: '#^Property Ibexa\\Bundle\\IO\\DependencyInjection\\Configuration\:\:\$metadataHandlerFactories with generic class ArrayObject does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Parameter \#2 \$offset of function array_splice expects int, int\|string given\.$#' + identifier: argument.type count: 1 - path: src/bundle/IO/DependencyInjection/Configuration.php + path: src/contracts/Collection/MutableArrayList.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\:\:addConfiguration\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\PathGeneratorInterface\:\:getStoragePathForField\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory.php + path: src/contracts/FieldType/BinaryBase/PathGeneratorInterface.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\:\:configureHandler\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\RouteAwarePathGenerator\:\:generate\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory.php + path: src/contracts/FieldType/BinaryBase/RouteAwarePathGenerator.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\:\:configureHandler\(\) has parameter \$config with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\RouteAwarePathGenerator\:\:getParameters\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory.php + path: src/contracts/FieldType/BinaryBase/RouteAwarePathGenerator.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\Flysystem\:\:addConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldStorage\:\:deleteFieldData\(\) has parameter \$fieldIds with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php + path: src/contracts/FieldType/FieldStorage.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\Flysystem\:\:configureHandler\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldStorage\:\:getFieldData\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php + path: src/contracts/FieldType/FieldStorage.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\Flysystem\:\:configureHandler\(\) has parameter \$config with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:applyDefaultSettings\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\MetadataHandler\\LegacyDFSCluster\:\:addConfiguration\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:applyDefaultValidatorConfiguration\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\MetadataHandler\\LegacyDFSCluster\:\:configureHandler\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:fieldSettingsFromHash\(\) has parameter \$fieldSettingsHash with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Method Ibexa\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\MetadataHandler\\LegacyDFSCluster\:\:configureHandler\(\) has parameter \$config with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:fieldSettingsToHash\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Method Ibexa\\Bundle\\IO\\EventListener\\StreamFileListener\:\:onKernelRequest\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:getRelations\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/EventListener/StreamFileListener.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Method Ibexa\\Bundle\\IO\\IbexaIOBundle\:\:getContainerExtension\(\) should return Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|null but returns Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|false\.$#' - identifier: return.type + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:validatorConfigurationFromHash\(\) has parameter \$validatorConfigurationHash with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/IbexaIOBundle.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Parameter \#2 \$offset of class LimitIterator constructor expects int, int\|null given\.$#' - identifier: argument.type + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:validatorConfigurationToHash\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/BinaryFileLister.php + path: src/contracts/FieldType/FieldType.php - - message: '#^Parameter \#3 \$limit of class LimitIterator constructor expects int, int\|null given\.$#' - identifier: argument.type + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:fieldSettingsFromHash\(\) has parameter \$fieldSettingsHash with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/BinaryFileLister.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\FileLister\\BinaryFileLister\:\:\$fileList \(Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileIteratorInterface\) does not accept Iterator\.$#' - identifier: assign.propertyType + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:fieldSettingsToHash\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/BinaryFileLister.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileIterator\\LegacyStorageFileIterator\:\:count\(\) should return int\<0, max\> but returns int\.$#' + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getEmptyValue\(\) should return Ibexa\\Contracts\\Core\\FieldType\\Value but returns object\.$#' identifier: return.type count: 1 - path: src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileIterator\\LegacyStorageFileIterator\:\:fetchRow\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getRelations\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Interface Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileIteratorInterface extends generic interface Iterator but does not specify its types\: TKey, TValue$#' - identifier: missingType.generics + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getSettingsSchema\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/FileIteratorInterface.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileRowReader\\LegacyStorageFileRowReader\:\:init\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getValidatorConfigurationSchema\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php + path: src/contracts/FieldType/Generic/Type.php - - message: '#^Parameter \#3 \$length of function substr expects int\|null, int\<0, max\>\|false given\.$#' - identifier: argument.type + message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:mapConstraintViolationList\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\FileLister\\FileRowReaderInterface\:\:init\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/IO/Migration/FileLister/FileRowReaderInterface.php - - - - message: '#^PHPDoc tag @param has invalid value \(\\Ibexa\\Contracts\\Core\\Variation\\VariationPathGenerator\)\: Unexpected token "\\n \* ", expected variable at offset 324 on line 6$#' - identifier: phpDoc.parseError - count: 1 - path: src/bundle/IO/Migration/FileLister/ImageFileLister.php - - - - message: '#^PHPDoc tag @param has invalid value \(\\Liip\\ImagineBundle\\Imagine\\Filter\\FilterConfiguration\)\: Unexpected token "\\n \* ", expected variable at offset 393 on line 7$#' - identifier: phpDoc.parseError - count: 1 - path: src/bundle/IO/Migration/FileLister/ImageFileLister.php - - - - message: '#^Parameter \#2 \$offset of class LimitIterator constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/IO/Migration/FileLister/ImageFileLister.php - - - - message: '#^Parameter \#3 \$limit of class LimitIterator constructor expects int, int\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/IO/Migration/FileLister/ImageFileLister.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\FileLister\\ImageFileLister\:\:\$imageFileList \(Ibexa\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileList\) does not accept Iterator\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/FileLister/ImageFileLister.php - - - - message: '#^Cannot call method getMessage\(\) on Throwable\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/bundle/IO/Migration/FileMigrator/FileMigrator.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logError\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logError\(\) has parameter \$message with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logInfo\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logInfo\(\) has parameter \$message with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logMissingFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:logMissingFile\(\) has parameter \$id with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$fromBinarydataHandler \(Ibexa\\Core\\IO\\IOBinarydataHandler\) does not accept object\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$fromMetadataHandler \(Ibexa\\Core\\IO\\IOMetadataHandler\) does not accept object\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$logger \(Psr\\Log\\LoggerInterface\) does not accept Psr\\Log\\LoggerInterface\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$logger \(Psr\\Log\\LoggerInterface\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$toBinarydataHandler \(Ibexa\\Core\\IO\\IOBinarydataHandler\) does not accept object\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Property Ibexa\\Bundle\\IO\\Migration\\MigrationHandler\:\:\$toMetadataHandler \(Ibexa\\Core\\IO\\IOMetadataHandler\) does not accept object\.$#' - identifier: assign.propertyType - count: 1 - path: src/bundle/IO/Migration/MigrationHandler.php - - - - message: '#^Method Ibexa\\Bundle\\LegacySearchEngine\\ApiLoader\\ConnectionFactory\:\:getConnection\(\) should return Doctrine\\DBAL\\Connection but returns object\.$#' - identifier: return.type - count: 1 - path: src/bundle/LegacySearchEngine/ApiLoader/ConnectionFactory.php - - - - message: '#^Parameter \#1 \$array of function array_keys expects array, array\|bool\|float\|int\|string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/LegacySearchEngine/ApiLoader/ConnectionFactory.php - - - - message: '#^Method Ibexa\\Bundle\\LegacySearchEngine\\IbexaLegacySearchEngineBundle\:\:getContainerExtension\(\) should return Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|null but returns Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface\|false\.$#' - identifier: return.type - count: 1 - path: src/bundle/LegacySearchEngine/IbexaLegacySearchEngineBundle.php - - - - message: '#^Call to an undefined method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:setOutput\(\)\.$#' - identifier: method.notFound - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:__construct\(\) has parameter \$installers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:cacheClear\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:checkPermissions\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:executeCommand\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:getInstaller\(\) has parameter \$type with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:getInstaller\(\) should return Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer but returns false\.$#' - identifier: return.type - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Command\\InstallPlatformCommand\:\:indexData\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Event\\Subscriber\\BuildSchemaSubscriber\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/RepositoryInstaller/Event/Subscriber/BuildSchemaSubscriber.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importBinaries\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importData\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\CoreInstaller\:\:importSchema\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/CoreInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:copyConfigurationFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:getKernelSQLFileForDBMS\(\) should return string but returns string\|false\.$#' - identifier: return.type - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:runQueriesFromFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:runQueriesFromFile\(\) has parameter \$file with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\DbBasedInstaller\:\:setOutput\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Parameter \#1 \$array of function array_filter expects array, list\\|false given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Parameter \#2 \$subject of function preg_split expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/bundle/RepositoryInstaller/Installer/DbBasedInstaller.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importBinaries\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/Installer.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importData\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/Installer.php - - - - message: '#^Method Ibexa\\Bundle\\RepositoryInstaller\\Installer\\Installer\:\:importSchema\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/bundle/RepositoryInstaller/Installer/Installer.php - - - - message: '#^Template type TValue is declared as covariant, but occurs in invariant position in property Ibexa\\Contracts\\Core\\Collection\\AbstractInMemoryCollection\:\:\$items\.$#' - identifier: generics.variance - count: 1 - path: src/contracts/Collection/AbstractInMemoryCollection.php - - - - message: '#^Parameter \#2 \$offset of function array_splice expects int, int\|string given\.$#' - identifier: argument.type - count: 1 - path: src/contracts/Collection/MutableArrayList.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\PathGeneratorInterface\:\:getStoragePathForField\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/contracts/FieldType/BinaryBase/PathGeneratorInterface.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\RouteAwarePathGenerator\:\:generate\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/BinaryBase/RouteAwarePathGenerator.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\RouteAwarePathGenerator\:\:getParameters\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/BinaryBase/RouteAwarePathGenerator.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldStorage\:\:deleteFieldData\(\) has parameter \$fieldIds with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldStorage.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldStorage\:\:getFieldData\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/contracts/FieldType/FieldStorage.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:applyDefaultSettings\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:applyDefaultValidatorConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:fieldSettingsFromHash\(\) has parameter \$fieldSettingsHash with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:fieldSettingsToHash\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:getRelations\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:validatorConfigurationFromHash\(\) has parameter \$validatorConfigurationHash with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\FieldType\:\:validatorConfigurationToHash\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/FieldType.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:fieldSettingsFromHash\(\) has parameter \$fieldSettingsHash with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:fieldSettingsToHash\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getEmptyValue\(\) should return Ibexa\\Contracts\\Core\\FieldType\\Value but returns object\.$#' - identifier: return.type - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getRelations\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getSettingsSchema\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:getValidatorConfigurationSchema\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:mapConstraintViolationList\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/FieldType/Generic/Type.php + path: src/contracts/FieldType/Generic/Type.php - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\Generic\\Type\:\:toHash\(\) return type has no value type specified in iterable type array\.$#' @@ -4944,12 +4092,6 @@ parameters: count: 1 path: src/contracts/FieldType/ValueSerializerInterface.php - - - message: '#^Method Ibexa\\Contracts\\Core\\IO\\BinaryFileCreateStruct\:\:setInputStream\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/contracts/IO/BinaryFileCreateStruct.php - - message: '#^Method Ibexa\\Contracts\\Core\\Limitation\\Target\\Builder\\VersionBuilder\:\:translateToAnyLanguageOf\(\) has parameter \$languageCodes with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -7122,66 +6264,6 @@ parameters: count: 2 path: src/lib/FieldType/ISBN/Type.php - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\AliasCleanerInterface\:\:removeAliases\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/AliasCleanerInterface.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:deleteBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/Legacy.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/Legacy.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:newBinaryCreateStructFromUploadedFile\(\) has parameter \$uploadedFile with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/FieldType/Image/IO/Legacy.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:setPrefix\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/Legacy.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:setPrefixes\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/Legacy.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\OptionsProvider\:\:getDraftImagesDir\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/OptionsProvider.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\OptionsProvider\:\:getPublishedImagesDir\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/OptionsProvider.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\OptionsProvider\:\:getStorageDir\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/OptionsProvider.php - - - - message: '#^Method Ibexa\\Core\\FieldType\\Image\\IO\\OptionsProvider\:\:getVarDir\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/FieldType/Image/IO/OptionsProvider.php - - message: '#^Cannot access offset ''id'' on array\|bool\|float\|int\|string\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -8532,372 +7614,6 @@ parameters: count: 1 path: src/lib/Helper/TranslationHelper.php - - - message: '#^Method Ibexa\\Core\\IO\\ConfigScopeChangeAwareIOService\:\:newBinaryCreateStructFromUploadedFile\(\) has parameter \$uploadedFile with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/ConfigScopeChangeAwareIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\Exception\\IOException\:\:__construct\(\) has parameter \$message with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/Exception/IOException.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\:\:create\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\:\:getContents\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOBinarydataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\Flysystem\:\:getContents\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOBinarydataHandler/Flysystem.php - - - - message: '#^Parameter \#2 \$e of class Ibexa\\Core\\IO\\Exception\\IOException constructor expects Exception\|null, League\\Flysystem\\FilesystemException given\.$#' - identifier: argument.type - count: 2 - path: src/lib/IO/IOBinarydataHandler/Flysystem.php - - - - message: '#^Parameter \#2 \$previous of class Ibexa\\Core\\IO\\Exception\\BinaryFileNotFoundException constructor expects Exception\|null, League\\Flysystem\\FilesystemException given\.$#' - identifier: argument.type - count: 3 - path: src/lib/IO/IOBinarydataHandler/Flysystem.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentBinaryDataHandler\:\:create\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentBinaryDataHandler\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentBinaryDataHandler\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentBinaryDataHandler\:\:getContents\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentBinaryDataHandler\:\:getHandler\(\) should return Ibexa\\Core\\IO\\IOBinarydataHandler but returns object\.$#' - identifier: return.type - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentMetadataHandler\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentMetadataHandler\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentMetadataHandler\:\:deleteDirectory\(\) has parameter \$spiPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentMetadataHandler\:\:getHandler\(\) should return Ibexa\\Core\\IO\\IOMetadataHandler but returns object\.$#' - identifier: return.type - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOBinarydataHandler\\SiteAccessDependentMetadataHandler\:\:getMimeType\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\:\:deleteDirectory\(\) has parameter \$spiPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\:\:getMimeType\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOMetadataHandler.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\Flysystem\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler/Flysystem.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\Flysystem\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler/Flysystem.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\Flysystem\:\:deleteDirectory\(\) has parameter \$spiPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOMetadataHandler/Flysystem.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\Flysystem\:\:getMimeType\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOMetadataHandler/Flysystem.php - - - - message: '#^Parameter \#2 \$e of class Ibexa\\Core\\IO\\Exception\\IOException constructor expects Exception\|null, League\\Flysystem\\FilesystemException given\.$#' - identifier: argument.type - count: 2 - path: src/lib/IO/IOMetadataHandler/Flysystem.php - - - - message: '#^Cannot access offset ''datatype'' on array\\|false\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:delete\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:getMimeType\(\) has parameter \$spiBinaryFileId with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:mapArrayToSPIBinaryFile\(\) has parameter \$properties with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Property Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:\$urlDecorator \(Ibexa\\Core\\IO\\UrlDecorator\) does not accept Ibexa\\Core\\IO\\UrlDecorator\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Property Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:\$urlDecorator \(Ibexa\\Core\\IO\\UrlDecorator\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:__construct\(\) has parameter \$settings with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:checkBinaryFileId\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:deleteBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:newBinaryCreateStructFromUploadedFile\(\) has parameter \$uploadedFile with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOService\:\:setPrefix\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Parameter \#1 \$buffer of method Ibexa\\Contracts\\Core\\IO\\MimeTypeDetector\:\:getFromBuffer\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Parameter \#2 \$length of function fread expects int\<1, max\>, int\<0, max\> given\.$#' - identifier: argument.type - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Property Ibexa\\Contracts\\Core\\IO\\BinaryFile\:\:\$uri \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: src/lib/IO/IOService.php - - - - message: '#^Property Ibexa\\Core\\IO\\IOService\:\:\$settings type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Property Ibexa\\Core\\IO\\Values\\BinaryFileCreateStruct\:\:\$mimeType \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/lib/IO/IOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOServiceInterface\:\:deleteBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOServiceInterface.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOServiceInterface\:\:deleteDirectory\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOServiceInterface.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOServiceInterface\:\:newBinaryCreateStructFromUploadedFile\(\) has parameter \$uploadedFile with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/IO/IOServiceInterface.php - - - - message: '#^Method Ibexa\\Core\\IO\\IOServiceInterface\:\:setPrefix\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/IOServiceInterface.php - - - - message: '#^Property Ibexa\\Core\\IO\\MimeTypeDetector\\FileInfo\:\:\$fileInfo \(finfo\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/lib/IO/MimeTypeDetector/FileInfo.php - - - - message: '#^Dead catch \- Ibexa\\Core\\IO\\Exception\\BinaryFileNotFoundException is never thrown in the try block\.$#' - identifier: catch.neverThrown - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\TolerantIOService\:\:deleteBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\TolerantIOService\:\:logMissingFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\TolerantIOService\:\:logMissingFile\(\) has parameter \$id with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\TolerantIOService\:\:setLogger\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Property Ibexa\\Contracts\\Core\\IO\\BinaryFile\:\:\$uri \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Property Ibexa\\Core\\IO\\TolerantIOService\:\:\$logger \(Psr\\Log\\LoggerInterface\) does not accept Psr\\Log\\LoggerInterface\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Property Ibexa\\Core\\IO\\TolerantIOService\:\:\$logger \(Psr\\Log\\LoggerInterface\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: src/lib/IO/TolerantIOService.php - - - - message: '#^Method Ibexa\\Core\\IO\\UrlDecorator\:\:undecorate\(\) has parameter \$uri with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/UrlDecorator.php - - - - message: '#^Method Ibexa\\Core\\IO\\UrlDecorator\\Prefix\:\:undecorate\(\) has parameter \$url with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/IO/UrlDecorator/Prefix.php - - message: '#^Method Ibexa\\Core\\Limitation\\BlockingLimitationType\:\:evaluate\(\) has Ibexa\\Contracts\\Core\\Repository\\Exceptions\\BadStateException in PHPDoc @throws tag but it''s not thrown\.$#' identifier: throws.unusedType @@ -10254,12 +8970,6 @@ parameters: count: 1 path: src/lib/MVC/Symfony/Templating/Twig/Extension/FileSizeExtension.php - - - message: '#^Method Ibexa\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ImageExtension\:\:getImageVariation\(\) should return Ibexa\\Contracts\\Core\\Variation\\Values\\Variation\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php - - message: '#^Method Ibexa\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\QueryRenderingExtension\:\:createControllerReference\(\) has parameter \$options with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -23131,1306 +21841,568 @@ parameters: path: tests/bundle/Core/EventListener/ContentDownloadRouteReferenceListenerTest.php - - message: '#^Call to an undefined method Exception\:\:setMessageTemplate\(\)\.$#' - identifier: method.notFound - count: 2 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Call to an undefined method Exception\:\:setParameters\(\)\.$#' - identifier: method.notFound - count: 2 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:badRequestExceptionProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:otherExceptionProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testBadRequestException\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testNotFoundException\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testOtherRepositoryException\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testUnauthorizedException\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testUntouchedException\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^PHPDoc tag @param for parameter \$exception with type Exception\|Ibexa\\Core\\Base\\Translatable is not subtype of native type Exception\.$#' - identifier: parameter.phpDocType - count: 2 - path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:indexPageProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexNotOnIndexPage\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$configuredIndexPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$expectedIndexPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$requestPath with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:onKernelRequestProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$configuredLanguages with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$convertedLocalesValueMap with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$expectedLocale with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Parameter \#1 \$requestStack of class Symfony\\Component\\HttpKernel\\EventListener\\LocaleListener constructor expects Symfony\\Component\\HttpFoundation\\RequestStack, Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface&PHPUnit\\Framework\\MockObject\\MockObject given\.$#' - identifier: argument.type - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:\$requestStack \(Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept Symfony\\Component\\HttpFoundation\\RequestStack\.$#' - identifier: assign.propertyType - count: 1 - path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestNoOriginalRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestNotMaster\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestWithOriginalRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RejectExplicitFrontControllerRequestsListenerTest\:\:prohibitedRequestDataProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/RejectExplicitFrontControllerRequestsListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RejectExplicitFrontControllerRequestsListenerTest\:\:validRequestDataProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/RejectExplicitFrontControllerRequestsListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestForward\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestForwardSubRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirect\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectPrependSiteaccess\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectSubRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectWithLocationId\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:\$event is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RoutingListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RoutingListenerTest\:\:testOnSiteAccessMatch\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - - - message: '#^Parameter \#1 \$configResolver of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' - identifier: argument.type - count: 2 - path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - - - message: '#^Parameter \#2 \$urlAliasRouter of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Symfony\\Component\\Routing\\RouterInterface, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' - identifier: argument.type - count: 2 - path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - - - message: '#^Parameter \#3 \$urlAliasGenerator of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Ibexa\\Core\\MVC\\Symfony\\Routing\\Generator, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' - identifier: argument.type - count: 2 - path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SessionSetDynamicNameListenerTest\:\:testOnSiteAccessMatch\(\) has parameter \$configuredSessionStorageOptions with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SessionSetDynamicNameListenerTest\:\:testOnSiteAccessMatch\(\) has parameter \$expectedSessionStorageOptions with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:siteAccessMatchProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedSemanticPathinfo with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedVPArray with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedVPString with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$uri with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$expectedViewParameters with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$semanticPathinfo with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$uri with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$vpString with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Parameter \#2 \$offset of function substr expects int, int\<1, max\>\|false given\.$#' - identifier: argument.type - count: 1 - path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\FooServiceInterface\:\:someMethod\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/Stubs/FooServiceInterface.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\FooServiceInterface\:\:someMethod\(\) has parameter \$arg with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/Stubs/FooServiceInterface.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:clear\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:doWrite\(\) has parameter \$message with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:doWrite\(\) has parameter \$newline with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:\$output has no type specified\.$#' - identifier: missingType.property - count: 1 - path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContent\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContent\(\) should return string but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContentView\(\) has parameter \$defaultParams with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContentView\(\) should return string but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderLocation\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderLocation\(\) should return string but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:setSiteAccess\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewProvider\:\:getView\(\) should return Ibexa\\Core\\MVC\\Symfony\\View\\View but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewProvider.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewProvider\:\:setSiteAccess\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/Stubs/ViewProvider.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerMatchedView\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerNoBuilder\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerWithClosure\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:\$controllerResolver \(PHPUnit\\Framework\\MockObject\\MockObject&Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver\) does not accept PHPUnit\\Framework\\MockObject\\MockObject&Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface\.$#' - identifier: assign.propertyType - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:\$viewConfigurator is unused\.$#' - identifier: property.unused - count: 1 - path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetLocale\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetLocale\(\) has parameter \$shouldHaveCustomLocale with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetRequestsProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:getTrustedHeaderEventSubscriberTestData\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:testTrustedHeaderEventSubscriberWithTrustedProxy\(\) has parameter \$headers with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:testTrustedHeaderEventSubscriberWithTrustedProxy\(\) has parameter \$server with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - - - message: '#^Parameter \#2 \$trustedHeaderSet of static method Symfony\\Component\\HttpFoundation\\Request\:\:setTrustedProxies\(\) expects int\<0, 63\>, \-1 given\.$#' - identifier: argument.type - count: 1 - path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - - - message: '#^Parameter \#2 \$trustedHeaderSet of static method Symfony\\Component\\HttpFoundation\\Request\:\:setTrustedProxies\(\) expects int\<0, 63\>, int given\.$#' - identifier: argument.type - count: 1 - path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - - - message: '#^Binary operation "\." between ''rendered_'' and \(Closure\(array\\)\: string\)\|string results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpFoundation\\\\Response'' and Symfony\\Component\\HttpFoundation\\Response will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 4 - path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:buildFragmentListenerProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has parameter \$isFragmentCandidate with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has parameter \$requestUri with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListenerNoRequest\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasCleanerTest\:\:testRemoveAliases\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasCleanerTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:supportsValueProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationAlreadyStored\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationInvalidVariation\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationNotStored\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationNotStoredHavingReferences\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationOriginal\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationOriginalNotFound\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testGetVariationWrongValue\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\AliasGeneratorTest\:\:testSupportsValue\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/AliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\BinaryLoaderTest\:\:testFindBadPathRoot\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/BinaryLoaderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\BinaryLoaderTest\:\:testFindMissing\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/BinaryLoaderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\BinaryLoaderTest\:\:testFindNotFound\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/BinaryLoaderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\Resolver\\ProxyResolverTest\:\:testResolveAndRemovePortUsingProxyHost\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\Resolver\\ProxyResolverTest\:\:testResolveAndRemovePortUsingProxyHostWithTrailingSlash\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\Resolver\\ProxyResolverTest\:\:testResolveUsingProxyHostWithTrailingSlash\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\Resolver\\RelativeResolverTest\:\:testResolve\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/Resolver/RelativeResolverTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\ResolverFactoryTest\:\:testCreateProxyCacheResolver\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Cache\\ResolverFactoryTest\:\:testCreateRelativeCacheResolver\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:getFilter\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:getSetOptionNoDefaulValueProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:getSetOptionWithDefaulValueProvider\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionNoDefaultValue\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionNoDefaultValue\(\) has parameter \$optionName with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionNoDefaultValue\(\) has parameter \$value with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionWithDefaultValue\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionWithDefaultValue\(\) has parameter \$defaultValue with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionWithDefaultValue\(\) has parameter \$optionName with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php + message: '#^Call to an undefined method Exception\:\:setMessageTemplate\(\)\.$#' + identifier: method.notFound + count: 2 + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptionWithDefaultValue\(\) has parameter \$value with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php + message: '#^Call to an undefined method Exception\:\:setParameters\(\)\.$#' + identifier: method.notFound + count: 2 + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\AbstractFilterTest\:\:testGetSetOptions\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:badRequestExceptionProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testAll\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:otherExceptionProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetEzVariationImagineFilters\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testBadRequestException\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetEzVariationImagineOptions\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetEzVariationNoReference\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testNotFoundException\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetEzVariationWithReference\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testOtherRepositoryException\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetNoEzVariationInvalidImagineFilter\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testUnauthorizedException\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\FilterConfigurationTest\:\:testGetOnlyImagineFilters\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ExceptionListenerTest\:\:testUntouchedException\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php + + - + message: '#^PHPDoc tag @param for parameter \$exception with type Exception\|Ibexa\\Core\\Base\\Translatable is not subtype of native type Exception\.$#' + identifier: parameter.phpDocType + count: 2 + path: tests/bundle/Core/EventListener/ExceptionListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:indexPageProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:loadProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexNotOnIndexPage\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoad\(\) has parameter \$color with no type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$configuredIndexPath with no type specified\.$#' identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoad\(\) has parameter \$thickX with no type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$expectedIndexPath with no type specified\.$#' identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoad\(\) has parameter \$thickY with no type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testOnKernelRequestIndexOnIndexPage\(\) has parameter \$requestPath with no type specified\.$#' identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoadDefaultColor\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\IndexRequestListenerTest\:\:testSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/IndexRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:onKernelRequestProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\BorderFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$configuredLanguages with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\CropFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$convertedLocalesValueMap with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\CropFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:testOnKernelRequest\(\) has parameter \$expectedLocale with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\CropFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Parameter \#1 \$requestStack of class Symfony\\Component\\HttpKernel\\EventListener\\LocaleListener constructor expects Symfony\\Component\\HttpFoundation\\RequestStack, Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface&PHPUnit\\Framework\\MockObject\\MockObject given\.$#' + identifier: argument.type count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\CropFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\LocaleListenerTest\:\:\$requestStack \(Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept Symfony\\Component\\HttpFoundation\\RequestStack\.$#' + identifier: assign.propertyType count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php + path: tests/bundle/Core/EventListener/LocaleListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\GrayscaleFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ReduceNoiseFilterLoaderTest\:\:testLoadInvalidDriver\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestNoOriginalRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoaderTest.php + path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleDownOnlyFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestNotMaster\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleDownOnlyFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\OriginalRequestListenerTest\:\:testOnKernelRequestWithOriginalRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/OriginalRequestListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleDownOnlyFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RejectExplicitFrontControllerRequestsListenerTest\:\:prohibitedRequestDataProvider\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RejectExplicitFrontControllerRequestsListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleDownOnlyFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RejectExplicitFrontControllerRequestsListenerTest\:\:validRequestDataProvider\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RejectExplicitFrontControllerRequestsListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleExactFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestForward\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleExactFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestForwardSubRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleExactFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirect\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleExactFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectPrependSiteaccess\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectSubRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoaderTest\:\:testLoadHeighten\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testOnKernelRequestRedirectWithLocationId\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:testSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\RequestEventListenerTest\:\:\$event is never read, only written\.$#' + identifier: property.onlyWritten count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RequestEventListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleFilterLoaderTest\:\:testLoadWiden\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RoutingListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightDownOnlyFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\RoutingListenerTest\:\:testOnSiteAccessMatch\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightDownOnlyFilterLoaderTest\:\:testLoadInvalid\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php + message: '#^Parameter \#1 \$configResolver of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Ibexa\\Contracts\\Core\\SiteAccess\\ConfigResolverInterface, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' + identifier: argument.type + count: 2 + path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php + message: '#^Parameter \#2 \$urlAliasRouter of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Symfony\\Component\\Routing\\RouterInterface, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' + identifier: argument.type + count: 2 + path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleHeightFilterLoaderTest\:\:testLoadFail\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php + message: '#^Parameter \#3 \$urlAliasGenerator of class Ibexa\\Bundle\\Core\\EventListener\\RoutingListener constructor expects Ibexa\\Core\\MVC\\Symfony\\Routing\\Generator, PHPUnit\\Framework\\MockObject\\MockObject given\.$#' + identifier: argument.type + count: 2 + path: tests/bundle/Core/EventListener/RoutingListenerTest.php - - message: '#^Method PHPUnit\\Framework\\TestCase\:\:createMock\(\) invoked with 2 parameters, 1 required\.$#' - identifier: arguments.count + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SessionSetDynamicNameListenerTest\:\:testOnSiteAccessMatch\(\) has parameter \$configuredSessionStorageOptions with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScalePercentFilterLoaderTest\:\:loadInvalidProvider\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SessionSetDynamicNameListenerTest\:\:testOnSiteAccessMatch\(\) has parameter \$expectedSessionStorageOptions with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScalePercentFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:siteAccessMatchProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScalePercentFilterLoaderTest\:\:testLoadInvalidOptions\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScalePercentFilterLoaderTest\:\:testLoadInvalidOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthDownOnlyFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthDownOnlyFilterLoaderTest\:\:testLoadInvalid\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedSemanticPathinfo with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthFilterLoaderTest\:\:testLoad\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedVPArray with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\ScaleWidthFilterLoaderTest\:\:testLoadFail\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$expectedVPString with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method PHPUnit\\Framework\\TestCase\:\:createMock\(\) invoked with 2 parameters, 1 required\.$#' - identifier: arguments.count + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchMasterRequest\(\) has parameter \$uri with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\SwirlFilterLoaderTest\:\:loadWithOptionProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\SwirlFilterLoaderTest\:\:testLoadNoOption\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$expectedViewParameters with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\SwirlFilterLoaderTest\:\:testLoadWithOption\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$semanticPathinfo with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\Loader\\SwirlFilterLoaderTest\:\:testLoadWithOption\(\) has parameter \$degrees with no type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$uri with no type specified\.$#' identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\Filter\\UnsupportedFilterTest\:\:testLoad\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\SiteAccessListenerTest\:\:testOnSiteAccessMatchSubRequest\(\) has parameter \$vpString with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/Filter/UnsupportedFilterTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\ImageAsset\\AliasGeneratorTest\:\:testGetVariationOfImageAsset\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Parameter \#2 \$offset of function substr expects int, int\<1, max\>\|false given\.$#' + identifier: argument.type count: 1 - path: tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php + path: tests/bundle/Core/EventListener/SiteAccessListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\ImageAsset\\AliasGeneratorTest\:\:testGetVariationOfNonImageAsset\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\FooServiceInterface\:\:someMethod\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/FooServiceInterface.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\ImageAsset\\AliasGeneratorTest\:\:testSupport\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\FooServiceInterface\:\:someMethod\(\) has parameter \$arg with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/FooServiceInterface.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorConfiguratorTest\:\:testConfigure\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:clear\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorConfiguratorTest.php + path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:getVariationProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:doWrite\(\) has parameter \$message with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:supportsValueProvider\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:doWrite\(\) has parameter \$newline with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationOriginalFound\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\TestOutput\:\:\$output has no type specified\.$#' + identifier: missingType.property count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/TestOutput.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationOriginalFound\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContent\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationOriginalNotFound\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationOriginalNotFound\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContent\(\) should return string but return statement is missing\.$#' + identifier: return.missing count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationReturnsPlaceholderIfBinaryDataIsNotAvailable\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContentView\(\) has parameter \$defaultParams with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationSkipsPlaceholderGeneration\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderContentView\(\) should return string but return statement is missing\.$#' + identifier: return.missing count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationSkipsPlaceholderGeneration\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderLocation\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testGetVariationWrongValue\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:renderLocation\(\) should return string but return statement is missing\.$#' + identifier: return.missing count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:testSupportsValue\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewManager\:\:setSiteAccess\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewManager.php - - message: '#^Property Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderAliasGeneratorTest\:\:\$placeholderOptions type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewProvider\:\:getView\(\) should return Ibexa\\Core\\MVC\\Symfony\\View\\View but return statement is missing\.$#' + identifier: return.missing count: 1 - path: tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewProvider.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:assertColorEquals\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\Stubs\\ViewProvider\:\:setSiteAccess\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:assertColorEquals\(\) has parameter \$expected with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/Stubs/ViewProvider.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:assertSizeEquals\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerMatchedView\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:assertSizeEquals\(\) has parameter \$expected with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerNoBuilder\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:getPlaceholderDataProvider\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetControllerWithClosure\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:testGetPlaceholder\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:testGetSubscribedEvents\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:testGetPlaceholder\(\) has parameter \$expectedText with no type specified\.$#' - identifier: missingType.parameter + message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:\$controllerResolver \(PHPUnit\\Framework\\MockObject\\MockObject&Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver\) does not accept PHPUnit\\Framework\\MockObject\\MockObject&Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface\.$#' + identifier: assign.propertyType count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProvider\\GenericProviderTest\:\:testGetPlaceholder\(\) has parameter \$options with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Property Ibexa\\Tests\\Bundle\\Core\\EventListener\\ViewControllerListenerTest\:\:\$viewConfigurator is unused\.$#' + identifier: property.unused count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php + path: tests/bundle/Core/EventListener/ViewControllerListenerTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistryTest\:\:testConstructor\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetLocale\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php + path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistryTest\:\:testGetProviderKnown\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetLocale\(\) has parameter \$shouldHaveCustomLocale with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php + path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistryTest\:\:testGetProviderUnknown\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\CrowdinRequestLocaleSubscriberTest\:\:testSetRequestsProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php + path: tests/bundle/Core/EventSubscriber/CrowdinRequestLocaleSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\PlaceholderProviderRegistryTest\:\:testSupports\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:getTrustedHeaderEventSubscriberTestData\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php + path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPathGenerator\\AliasDirectoryVariationPathGeneratorTest\:\:testGetVariationPath\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:testTrustedHeaderEventSubscriberWithTrustedProxy\(\) has parameter \$headers with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/VariationPathGenerator/AliasDirectoryVariationPathGeneratorTest.php + path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPathGenerator\\OriginalDirectoryVariationPathGeneratorTest\:\:testGetVariationPath\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:testTrustedHeaderEventSubscriberWithTrustedProxy\(\) has parameter \$server with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 - path: tests/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGeneratorTest.php + path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurgerTest\:\:createPurger\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Parameter \#2 \$trustedHeaderSet of static method Symfony\\Component\\HttpFoundation\\Request\:\:setTrustedProxies\(\) expects int\<0, 63\>, \-1 given\.$#' + identifier: argument.type count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php + path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurgerTest\:\:createPurger\(\) has parameter \$fileList with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Parameter \#2 \$trustedHeaderSet of static method Symfony\\Component\\HttpFoundation\\Request\:\:setTrustedProxies\(\) expects int\<0, 63\>, int given\.$#' + identifier: argument.type count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php + path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurgerTest\:\:testDoesNotPurgeNotExistingItem\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Binary operation "\." between ''rendered_'' and \(Closure\(array\\)\: string\)\|string results in an error\.$#' + identifier: binaryOp.invalid count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php + path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurgerTest\:\:testIteratesOverItems\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php + message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpFoundation\\\\Response'' and Symfony\\Component\\HttpFoundation\\Response will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 4 + path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\ImageFileVariationPurgerTest\:\:testPurgesExistingItem\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:buildFragmentListenerProvider\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php + path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileListTest\:\:configureRowReaderMock\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php + path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileListTest\:\:configureRowReaderMock\(\) has parameter \$fileList with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has parameter \$isFragmentCandidate with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php + path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileListTest\:\:testImageIdTransformation\(\) has no return type specified\.$#' - identifier: missingType.return + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListener\(\) has parameter \$requestUri with no type specified\.$#' + identifier: missingType.parameter count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php + path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - - message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Imagine\\VariationPurger\\LegacyStorageImageFileListTest\:\:testIterator\(\) has no return type specified\.$#' + message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:testBuildFragmentListenerNoRequest\(\) has no return type specified\.$#' identifier: missingType.return count: 1 - path: tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php + path: tests/bundle/Core/Fragment/FragmentListenerFactoryTest.php - message: '#^Cannot access offset ''path'' on array\{scheme\?\: string, host\?\: string, port\?\: int\<0, 65535\>, user\?\: string, pass\?\: string, path\?\: string, query\?\: string, fragment\?\: string\}\|false\.$#' @@ -24744,120 +22716,12 @@ parameters: count: 1 path: tests/bundle/Debug/DependencyInjection/Compiler/DataCollectorPassTest.php - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPassTest\:\:testBinarydataHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPassTest\:\:testDefaultHandlers\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPassTest\:\:testMetadataHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPassTest\:\:testUnknownBinarydataHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\Compiler\\IOConfigurationPassTest\:\:testUnknownMetadataHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\BaseFlysystemTestCase\:\:provideHandlerConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\BaseFlysystemTestCase\:\:validateConfiguredHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\BaseFlysystemTestCase\:\:\$flysystemAdapterServiceId has no type specified\.$#' - identifier: missingType.property - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\MetadataHandler\\LegacyDFSClusterTest\:\:provideHandlerConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactory\\MetadataHandler\\LegacyDFSClusterTest\:\:validateConfiguredHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php - - - - message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\ArrayNodeDefinition'' and Symfony\\Component\\Config\\Definition\\Builder\\ArrayNodeDefinition will always evaluate to true\.$#' - identifier: staticMethod.alreadyNarrowedType - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:provideExpectedParentServiceId\(\) has no return type specified\.$#' identifier: missingType.return count: 1 path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:provideHandlerConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:registerHandler\(\) has parameter \$name with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:testAddConfiguration\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:testConfigureHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:testGetParentServiceId\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\IO\\DependencyInjection\\ConfigurationFactoryTestCase\:\:validateConfiguredHandler\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - - - message: '#^PHPDoc tag @param references unknown parameter\: \$container$#' - identifier: parameter.notFound - count: 1 - path: tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php - - message: '#^Call to an undefined method object\:\:decorate\(\)\.$#' identifier: method.notFound @@ -24888,36 +22752,6 @@ parameters: count: 1 path: tests/bundle/IO/EventListener/StreamFileListenerTest.php - - - message: '#^Call to an undefined method Ibexa\\Core\\IO\\IOBinarydataHandler\\Flysystem\:\:expects\(\)\.$#' - identifier: method.notFound - count: 2 - path: tests/bundle/IO/Migration/FileMigratorTest.php - - - - message: '#^Call to an undefined method Ibexa\\Core\\IO\\IOMetadataHandler\\Flysystem\:\:expects\(\)\.$#' - identifier: method.notFound - count: 1 - path: tests/bundle/IO/Migration/FileMigratorTest.php - - - - message: '#^Call to an undefined method Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\:\:expects\(\)\.$#' - identifier: method.notFound - count: 1 - path: tests/bundle/IO/Migration/FileMigratorTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\IO\\Migration\\FileMigratorTest\:\:\$binaryFlysystemFrom \(Ibexa\\Core\\IO\\IOBinarydataHandler\\Flysystem\) does not accept Ibexa\\Core\\IO\\IOBinarydataHandler&PHPUnit\\Framework\\MockObject\\MockObject\.$#' - identifier: assign.propertyType - count: 1 - path: tests/bundle/IO/Migration/FileMigratorTest.php - - - - message: '#^Property Ibexa\\Tests\\Bundle\\IO\\Migration\\FileMigratorTest\:\:\$binaryFlysystemTo \(Ibexa\\Core\\IO\\IOBinarydataHandler\\Flysystem\) does not accept Ibexa\\Core\\IO\\IOBinarydataHandler&PHPUnit\\Framework\\MockObject\\MockObject\.$#' - identifier: assign.propertyType - count: 1 - path: tests/bundle/IO/Migration/FileMigratorTest.php - - message: '#^Method Ibexa\\Tests\\Integration\\Core\\BaseCoreFieldTypeIntegrationTestCase\:\:getDatabaseConnection\(\) should return Doctrine\\DBAL\\Connection but returns object\.$#' identifier: return.type @@ -43014,114 +40848,6 @@ parameters: count: 1 path: tests/lib/FieldType/Generic/Stubs/Value.php - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testCreateBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testDeleteBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testExists\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetFileContents\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetFileContentsOfDraft\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetFileInputStream\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetMimeType\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetMimeTypeOfDraft\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testGetUri\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFileByUriWithDraftFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFileByUriWithPublishedFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFileDraftExternalPath\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFileDraftInternalPath\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testLoadBinaryFilePublishedInternalPath\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testNewBinaryCreateStructFromLocalFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\IO\\LegacyTest\:\:testNewBinaryCreateStructFromUploadedFile\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - - - message: '#^Parameter \#1 \$binaryFileId of method Ibexa\\Core\\FieldType\\Image\\IO\\Legacy\:\:getUri\(\) expects string, Ibexa\\Core\\IO\\Values\\BinaryFile given\.$#' - identifier: argument.type - count: 1 - path: tests/lib/FieldType/Image/IO/LegacyTest.php - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Image\\PathGenerator\\LegacyPathGeneratorTest\:\:provideStoragePathForFieldData\(\) has no return type specified\.$#' identifier: missingType.return @@ -43650,24 +41376,6 @@ parameters: count: 1 path: tests/lib/IO/IOBinarydataHandler/FlysystemTest.php - - - message: '#^Parameter \#1 \$inputStream of method Ibexa\\Contracts\\Core\\IO\\BinaryFileCreateStruct\:\:setInputStream\(\) expects resource, resource\|false given\.$#' - identifier: argument.type - count: 1 - path: tests/lib/IO/IOBinarydataHandler/FlysystemTest.php - - - - message: '#^Property Ibexa\\Contracts\\Core\\IO\\BinaryFileCreateStruct\:\:\$mtime \(DateTime\) does not accept int\.$#' - identifier: assign.propertyType - count: 1 - path: tests/lib/IO/IOBinarydataHandler/FlysystemTest.php - - - - message: '#^Property Ibexa\\Tests\\Core\\IO\\IOBinarydataHandler\\FlysystemTest\:\:\$handler \(Ibexa\\Core\\IO\\IOBinarydataHandler&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept Ibexa\\Core\\IO\\IOBinarydataHandler\\Flysystem\.$#' - identifier: assign.propertyType - count: 1 - path: tests/lib/IO/IOBinarydataHandler/FlysystemTest.php - - message: '#^Method Ibexa\\Tests\\Core\\IO\\IOMetadataHandler\\FlysystemTest\:\:getDataForFileExists\(\) return type has no value type specified in iterable type iterable\.$#' identifier: missingType.iterableValue @@ -43686,36 +41394,6 @@ parameters: count: 1 path: tests/lib/IO/IOMetadataHandler/FlysystemTest.php - - - message: '#^Property Ibexa\\Contracts\\Core\\IO\\BinaryFileCreateStruct\:\:\$mtime \(DateTime\) does not accept int\.$#' - identifier: assign.propertyType - count: 1 - path: tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php - - - - message: '#^Property Ibexa\\Tests\\Core\\IO\\IOMetadataHandler\\LegacyDFSClusterTest\:\:\$handler \(Ibexa\\Core\\IO\\IOMetadataHandler&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept Ibexa\\Core\\IO\\IOMetadataHandler\\LegacyDFSCluster\.$#' - identifier: assign.propertyType - count: 1 - path: tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\IO\\MimeTypeDetector\\FileInfoTest\:\:testGetFromBuffer\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/IO/MimeTypeDetector/FileInfoTest.php - - - - message: '#^Method Ibexa\\Tests\\Core\\IO\\MimeTypeDetector\\FileInfoTest\:\:testGetFromPath\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: tests/lib/IO/MimeTypeDetector/FileInfoTest.php - - - - message: '#^Parameter \#1 \$path of method Ibexa\\Core\\IO\\MimeTypeDetector\\FileInfo\:\:getFromBuffer\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: tests/lib/IO/MimeTypeDetector/FileInfoTest.php - - message: '#^Method Ibexa\\Tests\\Core\\IO\\UrlDecorator\\AbsolutePrefixTest\:\:provideData\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/bundle/Core/Imagine/AliasCleaner.php b/src/bundle/Core/Imagine/AliasCleaner.php index 78ff42b9cf..369cfa09b6 100644 --- a/src/bundle/Core/Imagine/AliasCleaner.php +++ b/src/bundle/Core/Imagine/AliasCleaner.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; @@ -12,15 +13,14 @@ class AliasCleaner implements AliasCleanerInterface { - /** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $aliasResolver; + private ResolverInterface $aliasResolver; public function __construct(ResolverInterface $aliasResolver) { $this->aliasResolver = $aliasResolver; } - public function removeAliases($originalPath) + public function removeAliases(string $originalPath): void { $this->aliasResolver->remove([$originalPath], []); } diff --git a/src/bundle/Core/Imagine/AliasGenerator.php b/src/bundle/Core/Imagine/AliasGenerator.php index 97679a5049..d2ed16a37a 100644 --- a/src/bundle/Core/Imagine/AliasGenerator.php +++ b/src/bundle/Core/Imagine/AliasGenerator.php @@ -4,9 +4,11 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; +use Ibexa\Contracts\Core\Exception\InvalidArgumentException; use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException; use Ibexa\Contracts\Core\Repository\Values\Content\Field; @@ -17,7 +19,6 @@ use Ibexa\Core\FieldType\Image\Value as ImageValue; use Ibexa\Core\MVC\Exception\SourceImageNotFoundException; use Imagine\Exception\RuntimeException; -use InvalidArgumentException; use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Binary\Loader\LoaderInterface; use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; @@ -35,27 +36,21 @@ */ class AliasGenerator implements VariationHandler { - public const ALIAS_ORIGINAL = 'original'; + public const string ALIAS_ORIGINAL = 'original'; - /** @var \Psr\Log\LoggerInterface */ - private $logger; + private LoggerInterface $logger; /** * Loader used to retrieve the original image. * DataManager is not used to remain independent from ImagineBundle configuration. - * - * @var \Liip\ImagineBundle\Binary\Loader\LoaderInterface */ - private $dataLoader; + private LoaderInterface $dataLoader; - /** @var \Liip\ImagineBundle\Imagine\Filter\FilterManager */ - private $filterManager; + private FilterManager $filterManager; - /** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */ - private $filterConfiguration; + private FilterConfiguration $filterConfiguration; - /** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $ioResolver; + private ResolverInterface $ioResolver; public function __construct( LoaderInterface $dataLoader, @@ -68,16 +63,9 @@ public function __construct( $this->filterManager = $filterManager; $this->ioResolver = $ioResolver; $this->filterConfiguration = $filterConfiguration; - $this->logger = null !== $logger ? $logger : new NullLogger(); + $this->logger = $logger ?? new NullLogger(); } - /** - * {@inheritdoc} - * - * @throws \InvalidArgumentException If field value is not an instance of {@see \Ibexa\Core\FieldType\Image\Value}. - * @throws \Ibexa\Core\MVC\Exception\SourceImageNotFoundException If source image cannot be found. - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException If a problem occurs with generated variation. - */ public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation { /** @var \Ibexa\Core\FieldType\Image\Value $imageValue */ @@ -85,7 +73,10 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var $fieldId = $field->id; $fieldDefIdentifier = $field->fieldDefIdentifier; if (!$this->supportsValue($imageValue)) { - throw new InvalidArgumentException("Value of Field with ID $fieldId ($fieldDefIdentifier) cannot be used for generating an image variation."); + throw new InvalidArgumentException( + '$field', + "Value of Field with ID $fieldId ($fieldDefIdentifier) cannot be used for generating an image variation." + ); } $originalPath = $imageValue->id; @@ -98,6 +89,17 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var } catch (NotLoadableException $e) { throw new SourceImageNotFoundException((string)$originalPath, 0, $e); } + if (!$originalBinary instanceof BinaryInterface) { + throw new InvalidArgumentException( + '$field', + sprintf( + 'Data loader for \'%s\' path loaded %s instead of %s', + $originalPath, + get_debug_type($originalBinary), + BinaryInterface::class + ) + ); + } $this->logger->debug("Generating '$variationName' variation on $originalPath, field #$fieldId ($fieldDefIdentifier)"); @@ -145,13 +147,8 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var * An Ibexa variation may have a "reference". * In that case, reference's filters are applied first, recursively (a reference may also have another reference). * Reference must be a valid variation name, configured in Ibexa or in LiipImagineBundle. - * - * @param \Liip\ImagineBundle\Binary\BinaryInterface $image - * @param string $variationName - * - * @return \Liip\ImagineBundle\Binary\BinaryInterface */ - private function applyFilter(BinaryInterface $image, $variationName) + private function applyFilter(BinaryInterface $image, string $variationName): BinaryInterface { $filterConfig = $this->filterConfiguration->get($variationName); // If the variation has a reference, we recursively call this method to apply reference's filters. diff --git a/src/bundle/Core/Imagine/BinaryLoader.php b/src/bundle/Core/Imagine/BinaryLoader.php index 48d7cf755a..b05ad190a6 100644 --- a/src/bundle/Core/Imagine/BinaryLoader.php +++ b/src/bundle/Core/Imagine/BinaryLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; @@ -11,6 +12,7 @@ use Ibexa\Core\IO\Exception\InvalidBinaryFileIdException; use Ibexa\Core\IO\IOServiceInterface; use Ibexa\Core\IO\Values\MissingBinaryFile; +use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Binary\Loader\LoaderInterface; use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; use Liip\ImagineBundle\Model\Binary; @@ -22,11 +24,9 @@ */ class BinaryLoader implements LoaderInterface { - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $ioService; + private IOServiceInterface $ioService; - /** @var \Symfony\Component\Mime\MimeTypesInterface */ - private $mimeTypes; + private MimeTypesInterface $mimeTypes; public function __construct(IOServiceInterface $ioService, MimeTypesInterface $mimeTypes) { @@ -36,10 +36,8 @@ public function __construct(IOServiceInterface $ioService, MimeTypesInterface $m /** * @param string $path - * - * @return \Liip\ImagineBundle\Binary\BinaryInterface */ - public function find($path) + public function find($path): BinaryInterface { try { $binaryFile = $this->ioService->loadBinaryFile($path); @@ -52,8 +50,8 @@ public function find($path) return new Binary( $this->ioService->getFileContents($binaryFile), - $mimeType, - $this->mimeTypes->getExtensions($mimeType)[0] ?? null + $mimeType ?? '', + $this->mimeTypes->getExtensions($mimeType ?? '')[0] ?? null ); } catch (InvalidBinaryFileIdException $e) { $message = diff --git a/src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php b/src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php index a149702054..b54c152e0f 100644 --- a/src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php +++ b/src/bundle/Core/Imagine/Cache/AliasGeneratorDecorator.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Cache; @@ -22,35 +23,24 @@ */ class AliasGeneratorDecorator implements VariationHandler, SiteAccessAware { - private const IMAGE_VARIATION_IDENTIFIER = 'image_variation'; - private const IMAGE_VARIATION_SITEACCESS_IDENTIFIER = 'image_variation_siteaccess'; - private const IMAGE_VARIATION_CONTENT_IDENTIFIER = 'image_variation_content'; - private const IMAGE_VARIATION_FIELD_IDENTIFIER = 'image_variation_field'; - private const IMAGE_VARIATION_NAME_IDENTIFIER = 'image_variation_name'; - private const CONTENT_IDENTIFIER = 'content'; - private const CONTENT_VERSION_IDENTIFIER = 'content_version'; + private const string IMAGE_VARIATION_IDENTIFIER = 'image_variation'; + private const string IMAGE_VARIATION_SITEACCESS_IDENTIFIER = 'image_variation_siteaccess'; + private const string IMAGE_VARIATION_CONTENT_IDENTIFIER = 'image_variation_content'; + private const string IMAGE_VARIATION_FIELD_IDENTIFIER = 'image_variation_field'; + private const string IMAGE_VARIATION_NAME_IDENTIFIER = 'image_variation_name'; + private const string CONTENT_IDENTIFIER = 'content'; + private const string CONTENT_VERSION_IDENTIFIER = 'content_version'; - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $aliasGenerator; + private VariationHandler $aliasGenerator; - /** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */ - private $cache; + private TagAwareAdapterInterface $cache; - /** @var \Ibexa\Core\MVC\Symfony\SiteAccess */ - private $siteAccess; + private ?SiteAccess $siteAccess = null; - /** @var \Symfony\Component\Routing\RequestContext */ - private $requestContext; + private RequestContext $requestContext; - /** @var \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface */ - private $cacheIdentifierGenerator; + private CacheIdentifierGeneratorInterface $cacheIdentifierGenerator; - /** - * @param \Ibexa\Contracts\Core\Variation\VariationHandler $aliasGenerator - * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache - * @param \Symfony\Component\Routing\RequestContext $requestContext - * @param \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface $cacheIdentifierGenerator - */ public function __construct( VariationHandler $aliasGenerator, TagAwareAdapterInterface $cache, @@ -64,17 +54,18 @@ public function __construct( } /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field - * @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo - * @param string $variationName - * @param array $parameters - * - * @return \Ibexa\Contracts\Core\Variation\Values\Variation - * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException + * @throws \Psr\Cache\CacheException * @throws \Psr\Cache\InvalidArgumentException */ - public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation - { + public function getVariation( + Field $field, + VersionInfo $versionInfo, + string $variationName, + array $parameters = [] + ): Variation { $item = $this->cache->getItem($this->getCacheKey($field, $versionInfo, $variationName)); $image = $item->get(); if (!$item->isHit()) { @@ -90,19 +81,15 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var /** * @param \Ibexa\Core\MVC\Symfony\SiteAccess|null $siteAccess */ - public function setSiteAccess(SiteAccess $siteAccess = null) + public function setSiteAccess(?SiteAccess $siteAccess = null): void { $this->siteAccess = $siteAccess; } /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field - * @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo - * @param string $variationName - * - * @return string + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - private function getCacheKey(Field $field, VersionInfo $versionInfo, $variationName): string + private function getCacheKey(Field $field, VersionInfo $versionInfo, string $variationName): string { return sprintf( $this->cacheIdentifierGenerator->generateKey(self::IMAGE_VARIATION_IDENTIFIER, [], true) . '-%s-%s-%s-%d-%d-%d-%s-%s', @@ -117,6 +104,11 @@ private function getCacheKey(Field $field, VersionInfo $versionInfo, $variationN ); } + /** + * @return string[] + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ private function getTagsForVariation(Field $field, VersionInfo $versionInfo, string $variationName): array { $contentId = $versionInfo->getContentInfo()->id; diff --git a/src/bundle/Core/Imagine/Cache/Resolver/ProxyResolver.php b/src/bundle/Core/Imagine/Cache/Resolver/ProxyResolver.php index b2eeee613f..e231bb24d8 100644 --- a/src/bundle/Core/Imagine/Cache/Resolver/ProxyResolver.php +++ b/src/bundle/Core/Imagine/Cache/Resolver/ProxyResolver.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Cache\Resolver; @@ -14,14 +15,14 @@ class ProxyResolver extends ImagineProxyResolver /** * Replaces host with given proxy host. * - * The original method from Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver:rewriteUrl() + * The original method from `\Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver::rewriteUrl()` * doesn't behave correctly when working with domain and port or with host which contains trailing slash. * - * @param string $url + * @see \Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver::rewriteUrl * - * @return string + * @param string $url */ - protected function rewriteUrl($url) + protected function rewriteUrl($url): string { if (empty($this->hosts)) { return $url; diff --git a/src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php b/src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php index bfb59d333e..4afb915c57 100644 --- a/src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php +++ b/src/bundle/Core/Imagine/Cache/Resolver/RelativeResolver.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Cache\Resolver; @@ -15,9 +16,6 @@ */ class RelativeResolver extends ImagineProxyResolver { - /** - * @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver - */ public function __construct(ResolverInterface $resolver) { parent::__construct($resolver, []); @@ -27,10 +25,8 @@ public function __construct(ResolverInterface $resolver) * Returns relative image path. * * @param $url string - * - * @return string */ - protected function rewriteUrl($url) + protected function rewriteUrl($url): string { return parse_url($url, PHP_URL_PATH); } diff --git a/src/bundle/Core/Imagine/Cache/ResolverFactory.php b/src/bundle/Core/Imagine/Cache/ResolverFactory.php index d6666ffa4e..ad2150f56a 100644 --- a/src/bundle/Core/Imagine/Cache/ResolverFactory.php +++ b/src/bundle/Core/Imagine/Cache/ResolverFactory.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Cache; @@ -12,32 +13,25 @@ class ResolverFactory { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $resolver; + private ResolverInterface $resolver; - /** @var string|null */ - private $resolverDecoratorClass; + /** @phpstan-var class-string<\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface> */ + private string $proxyResolverClass; - /** @var string */ - private $proxyResolverClass; - - /** @var string */ - private $relativeResolverClass; + /** @phpstan-var class-string<\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface> */ + private string $relativeResolverClass; /** - * @param \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface $configResolver - * @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver - * @param string $proxyResolverClass - * @param string $relativeResolverClass + * @phpstan-param class-string<\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface> $proxyResolverClass + * @phpstan-param class-string<\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface> $relativeResolverClass */ public function __construct( ConfigResolverInterface $configResolver, ResolverInterface $resolver, - $proxyResolverClass, - $relativeResolverClass + string $proxyResolverClass, + string $relativeResolverClass ) { $this->configResolver = $configResolver; $this->resolver = $resolver; @@ -48,7 +42,7 @@ public function __construct( /** * @return \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - public function createCacheResolver() + public function createCacheResolver(): ResolverInterface { $imageHost = $this->configResolver->hasParameter('image_host') ? $this->configResolver->getParameter('image_host') : @@ -59,11 +53,11 @@ public function createCacheResolver() } if ($imageHost === '/') { - $this->resolverDecoratorClass = $this->relativeResolverClass; + $resolverDecoratorClass = $this->relativeResolverClass; } else { - $this->resolverDecoratorClass = $this->proxyResolverClass; + $resolverDecoratorClass = $this->proxyResolverClass; } - return new $this->resolverDecoratorClass($this->resolver, [$imageHost]); + return new $resolverDecoratorClass($this->resolver, [$imageHost]); } } diff --git a/src/bundle/Core/Imagine/Filter/AbstractFilter.php b/src/bundle/Core/Imagine/Filter/AbstractFilter.php index 2a0956a27f..dffd7179cd 100644 --- a/src/bundle/Core/Imagine/Filter/AbstractFilter.php +++ b/src/bundle/Core/Imagine/Filter/AbstractFilter.php @@ -12,35 +12,34 @@ */ abstract class AbstractFilter implements FilterInterface { - /** @var array */ - private $options; - - public function __construct(array $options = []) + /** + * @phpstan-param array $options + */ + public function __construct(private array $options = []) { - $this->options = $options; } - public function setOption($optionName, $value) + public function setOption(string $optionName, mixed $value): void { $this->options[$optionName] = $value; } - public function getOption($optionName, $defaultValue = null) + public function getOption(string $optionName, mixed $defaultValue = null): mixed { - return isset($this->options[$optionName]) ? $this->options[$optionName] : $defaultValue; + return $this->options[$optionName] ?? $defaultValue; } - public function hasOption($optionName) + public function hasOption(string $optionName): bool { return isset($this->options[$optionName]); } - public function setOptions(array $options) + public function setOptions(array $options): void { $this->options = $options; } - public function getOptions() + public function getOptions(): array { return $this->options; } diff --git a/src/bundle/Core/Imagine/Filter/FilterConfiguration.php b/src/bundle/Core/Imagine/Filter/FilterConfiguration.php index 22ab6b5596..8d930627b3 100644 --- a/src/bundle/Core/Imagine/Filter/FilterConfiguration.php +++ b/src/bundle/Core/Imagine/Filter/FilterConfiguration.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter; @@ -12,18 +13,17 @@ class FilterConfiguration extends BaseFilterConfiguration { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** - * @param \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface $configResolver - */ - public function setConfigResolver(ConfigResolverInterface $configResolver) + public function setConfigResolver(ConfigResolverInterface $configResolver): void { $this->configResolver = $configResolver; } - public function get($filter) + /** + * @return array + */ + public function get($filter): array { $configuredVariations = $this->configResolver->getParameter('image_variations'); if (!array_key_exists($filter, $configuredVariations)) { @@ -35,13 +35,16 @@ public function get($filter) return [ 'cache' => 'ibexa', 'data_loader' => 'ibexa', - 'reference' => isset($configuredVariations[$filter]['reference']) ? $configuredVariations[$filter]['reference'] : null, + 'reference' => $configuredVariations[$filter]['reference'] ?? null, 'filters' => $this->getVariationFilters($filter, $configuredVariations), 'post_processors' => $this->getVariationPostProcessors($filter, $configuredVariations), ] + $filterConfig; } - public function all() + /** + * @return array + */ + public function all(): array { return $this->configResolver->getParameter('image_variations') + parent::all(); } @@ -52,26 +55,18 @@ public function all() * Both variations configured in Ibexa (SiteAccess context) and LiipImagineBundle are used. * Ibexa variations always have precedence. * - * @param string $variationName - * @param array $configuredVariations Variations set in eZ. + * @param array}> $configuredVariations Variations set in eZ. * - * @return array + * @return array */ - private function getVariationFilters($variationName, array $configuredVariations) + private function getVariationFilters(string $variationName, array $configuredVariations): array { if (!isset($configuredVariations[$variationName]['filters']) && !isset($this->filters[$variationName]['filters'])) { return []; } // Check variations configured in Ibexa config first. - if (isset($configuredVariations[$variationName]['filters'])) { - $filters = $configuredVariations[$variationName]['filters']; - } else { - // Falback to variations configured in LiipImagineBundle. - $filters = $this->filters[$variationName]['filters']; - } - - return $filters; + return $configuredVariations[$variationName]['filters'] ?? $this->filters[$variationName]['filters']; } /** @@ -80,19 +75,14 @@ private function getVariationFilters($variationName, array $configuredVariations * Both variations configured in Ibexa and LiipImagineBundle are used. * Ibexa variations always have precedence. * - * @param string $variationName - * @param array $configuredVariations Variations set in eZ. + * @param array}> $configuredVariations Variations set in Ibexa. * - * @return array + * @return array */ - private function getVariationPostProcessors($variationName, array $configuredVariations) + private function getVariationPostProcessors(string $variationName, array $configuredVariations): array { - if (isset($configuredVariations[$variationName]['post_processors'])) { - return $configuredVariations[$variationName]['post_processors']; - } elseif (isset($this->filters[$variationName]['post_processors'])) { - return $this->filters[$variationName]['post_processors']; - } - - return []; + return $configuredVariations[$variationName]['post_processors'] + ?? $this->filters[$variationName]['post_processors'] + ?? []; } } diff --git a/src/bundle/Core/Imagine/Filter/FilterInterface.php b/src/bundle/Core/Imagine/Filter/FilterInterface.php index 0396468396..b8928edb31 100644 --- a/src/bundle/Core/Imagine/Filter/FilterInterface.php +++ b/src/bundle/Core/Imagine/Filter/FilterInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter; @@ -13,43 +14,31 @@ interface FilterInterface extends BaseFilterInterface { /** * Sets $value for $optionName. - * - * @param string $optionName - * @param mixed $value */ - public function setOption($optionName, $value); + public function setOption(string $optionName, mixed $value): void; /** * Returns value for $optionName. * Defaults to $defaultValue if $optionName doesn't exist. - * - * @param string $optionName - * @param mixed|null $defaultValue - * - * @return mixed */ - public function getOption($optionName, $defaultValue = null); + public function getOption(string $optionName, mixed $defaultValue = null): mixed; /** * Checks if $optionName exists and has a value. - * - * @param string $optionName - * - * @return bool */ - public function hasOption($optionName); + public function hasOption(string $optionName): bool; /** * Replaces inner options by $options. * - * @param array $options + * @phpstan-param array $options */ - public function setOptions(array $options); + public function setOptions(array $options): void; /** * Returns all options. * - * @return array + * @return array */ - public function getOptions(); + public function getOptions(): array; } diff --git a/src/bundle/Core/Imagine/Filter/Gmagick/ReduceNoiseFilter.php b/src/bundle/Core/Imagine/Filter/Gmagick/ReduceNoiseFilter.php index c57da06e43..68d9738b88 100644 --- a/src/bundle/Core/Imagine/Filter/Gmagick/ReduceNoiseFilter.php +++ b/src/bundle/Core/Imagine/Filter/Gmagick/ReduceNoiseFilter.php @@ -4,24 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Gmagick; use Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter; +use Imagine\Gmagick\Image; use Imagine\Image\ImageInterface; class ReduceNoiseFilter extends AbstractFilter { /** - * @param \Imagine\Image\ImageInterface|\Imagine\Gmagick\Image $image - * - * @return \Imagine\Image\ImageInterface + * @throws \GmagickException */ - public function apply(ImageInterface $image) + public function apply(ImageInterface $image): ImageInterface { - /** @var \Gmagick $gmagick */ - $gmagick = $image->getGmagick(); - $gmagick->reduceNoiseImage((float)$this->getOption('radius', 0)); + if ($image instanceof Image) { + $gmagick = $image->getGmagick(); + $gmagick->reduceNoiseImage((float)$this->getOption('radius', 0)); + } return $image; } diff --git a/src/bundle/Core/Imagine/Filter/Gmagick/SwirlFilter.php b/src/bundle/Core/Imagine/Filter/Gmagick/SwirlFilter.php index 39290e0f10..3ac31aa52c 100644 --- a/src/bundle/Core/Imagine/Filter/Gmagick/SwirlFilter.php +++ b/src/bundle/Core/Imagine/Filter/Gmagick/SwirlFilter.php @@ -4,24 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Gmagick; use Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter; +use Imagine\Gmagick\Image; use Imagine\Image\ImageInterface; class SwirlFilter extends AbstractFilter { /** - * @param \Imagine\Image\ImageInterface|\Imagine\Gmagick\Image $image - * - * @return \Imagine\Image\ImageInterface + * @throws \GmagickException */ - public function apply(ImageInterface $image) + public function apply(ImageInterface $image): ImageInterface { - /** @var \Gmagick $gmagick */ - $gmagick = $image->getGmagick(); - $gmagick->swirlimage((float)$this->getOption('degrees', 60)); + if ($image instanceof Image) { + $gmagick = $image->getGmagick(); + $gmagick->swirlimage((float)$this->getOption('degrees', 60)); + } return $image; } diff --git a/src/bundle/Core/Imagine/Filter/Imagick/ReduceNoiseFilter.php b/src/bundle/Core/Imagine/Filter/Imagick/ReduceNoiseFilter.php index b0858347c9..2d150ba1d5 100644 --- a/src/bundle/Core/Imagine/Filter/Imagick/ReduceNoiseFilter.php +++ b/src/bundle/Core/Imagine/Filter/Imagick/ReduceNoiseFilter.php @@ -4,24 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Imagick; use Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter; use Imagine\Image\ImageInterface; +use Imagine\Imagick\Image; class ReduceNoiseFilter extends AbstractFilter { /** - * @param \Imagine\Image\ImageInterface|\Imagine\Imagick\Image $image - * - * @return \Imagine\Image\ImageInterface + * @throws \ImagickException */ - public function apply(ImageInterface $image) + public function apply(ImageInterface $image): ImageInterface { - /** @var \Imagick $imagick */ - $imagick = $image->getImagick(); - $imagick->reduceNoiseImage((float)$this->getOption('radius', 0)); + if ($image instanceof Image) { + $imagick = $image->getImagick(); + $imagick->reduceNoiseImage((float)$this->getOption('radius', 0)); + } return $image; } diff --git a/src/bundle/Core/Imagine/Filter/Imagick/SwirlFilter.php b/src/bundle/Core/Imagine/Filter/Imagick/SwirlFilter.php index 4c75ea173e..d78a59b527 100644 --- a/src/bundle/Core/Imagine/Filter/Imagick/SwirlFilter.php +++ b/src/bundle/Core/Imagine/Filter/Imagick/SwirlFilter.php @@ -4,24 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Imagick; use Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter; use Imagine\Image\ImageInterface; +use Imagine\Imagick\Image; class SwirlFilter extends AbstractFilter { /** - * @param \Imagine\Image\ImageInterface|\Imagine\Imagick\Image $image - * - * @return \Imagine\Image\ImageInterface + * @throws \ImagickException */ - public function apply(ImageInterface $image) + public function apply(ImageInterface $image): Image|ImageInterface { - /** @var \Imagick $imagick */ - $imagick = $image->getImagick(); - $imagick->swirlImage((float)$this->getOption('degrees', 60)); + if ($image instanceof Image) { + $imagick = $image->getImagick(); + $imagick->swirlImage((float)$this->getOption('degrees', 60)); + } return $image; } diff --git a/src/bundle/Core/Imagine/Filter/Loader/BorderFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/BorderFilterLoader.php index 6baf9cf2cb..8324daa8a9 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/BorderFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/BorderFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -20,26 +21,26 @@ */ class BorderFilterLoader implements LoaderInterface { - public const IDENTIFIER = 'border'; + public const string IDENTIFIER = 'border'; - public const DEFAULT_BORDER_COLOR = '#000'; + public const string DEFAULT_BORDER_COLOR = '#000'; + /** + * @phpstan-param array{0?: int, 1?: int, 2?: string} $options + */ public function load(ImageInterface $image, array $options = []): ImageInterface { - $optionsCount = count($options); - if ($optionsCount < 2) { + if (!isset($options[0], $options[1])) { throw new InvalidArgumentException('Invalid options for border filter. You must provide array(width, height)'); } $color = static::DEFAULT_BORDER_COLOR; - if ($optionsCount > 2) { - list($width, $height, $color) = $options; + if (isset($options[2])) { + [$width, $height, $color] = $options; } else { - list($width, $height) = $options; + [$width, $height] = $options; } - $border = new Border($image->palette()->color($color), $width, $height); - - return $border->apply($image); + return (new Border($image->palette()->color($color), $width, $height))->apply($image); } } diff --git a/src/bundle/Core/Imagine/Filter/Loader/CropFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/CropFilterLoader.php index 8819f32884..8f6c674405 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/CropFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/CropFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class CropFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/crop'; + public const string IDENTIFIER = 'geometry/crop'; + /** + * @phpstan-param array{0?: int, 1?: int, 2?: int, 3?: int} $options + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (count($options) < 4) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/FilterLoaderWrapped.php b/src/bundle/Core/Imagine/Filter/Loader/FilterLoaderWrapped.php index 5aa4c68170..046eca4014 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/FilterLoaderWrapped.php +++ b/src/bundle/Core/Imagine/Filter/Loader/FilterLoaderWrapped.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -11,13 +12,9 @@ abstract class FilterLoaderWrapped implements LoaderInterface { - /** @var \Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface */ - protected $innerLoader; + protected LoaderInterface $innerLoader; - /** - * @param \Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface $innerLoader - */ - public function setInnerLoader(LoaderInterface $innerLoader) + public function setInnerLoader(LoaderInterface $innerLoader): void { $this->innerLoader = $innerLoader; } diff --git a/src/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoader.php index 39ee09b4e9..a9a3418824 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class GrayscaleFilterLoader implements LoaderInterface { - public const IDENTIFIER = 'colorspace/gray'; + public const string IDENTIFIER = 'colorspace/gray'; + /** + * @param array{} $options + */ public function load(ImageInterface $image, array $options = []): ImageInterface { $image->effects()->grayscale(); diff --git a/src/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoader.php index b4e2af766c..9db0609f97 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -20,16 +21,18 @@ */ class ReduceNoiseFilterLoader implements LoaderInterface { - public const IDENTIFIER = 'filter/noise'; + public const string IDENTIFIER = 'filter/noise'; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterInterface */ - private $filter; + private FilterInterface $filter; public function __construct(FilterInterface $filter) { $this->filter = $filter; } + /** + * @phpstan-param array{0?: int} $options radius + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (!$image instanceof ImagickImage && !$image instanceof GmagickImage) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoader.php index 294045dcf9..6ae55fb009 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,17 +17,14 @@ */ class ScaleDownOnlyFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scaledownonly'; + public const string IDENTIFIER = 'geometry/scaledownonly'; /** * Loads and applies a filter on the given image. * - * @param \Imagine\Image\ImageInterface $image - * @param array $options Numerically indexed array. First entry is width, second is height. + * @param array{0?: int, 1?: int} $options Numerically indexed array. The First entry is width, the second is height. * * @throws \Imagine\Exception\InvalidArgumentException - * - * @return \Imagine\Image\ImageInterface */ public function load(ImageInterface $image, array $options = []): ImageInterface { diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoader.php index cf2657d9bd..39bdf15f7b 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class ScaleExactFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scaleexact'; + public const string IDENTIFIER = 'geometry/scaleexact'; + /** + * @phpstan-param array{0?: int, 1?: int} $options width, height + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (count($options) < 2) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoader.php index 81796692a2..db4d6ed382 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,15 +17,18 @@ */ class ScaleFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scale'; + public const string IDENTIFIER = 'geometry/scale'; + /** + * @phpstan-param array{0?: int, 1?: int} $options width, height + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (count($options) < 2) { throw new InvalidArgumentException('Missing width and/or height options'); } - list($width, $height) = $options; + [$width, $height] = $options; $size = $image->getSize(); $ratioWidth = $width / $size->getWidth(); $ratioHeight = $height / $size->getHeight(); diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoader.php index 5d3f127de9..aacbc16b87 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class ScaleHeightDownOnlyFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scaleheightdownonly'; + public const string IDENTIFIER = 'geometry/scaleheightdownonly'; + /** + * @phpstan-param array{0?: int} $options height + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (empty($options)) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoader.php index 01a8badb23..5482d2b209 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,12 +17,15 @@ */ class ScaleHeightFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scaleheight'; + public const string IDENTIFIER = 'geometry/scaleheight'; + /** + * @phpstan-param array{0?: int} $options height + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (empty($options)) { - throw new InvalidArgumentException('Missing width option'); + throw new InvalidArgumentException('Missing height option'); } return $this->innerLoader->load($image, ['heighten' => $options[0]]); diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoader.php index b9c6c2419e..63dea55c69 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class ScalePercentFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scalepercent'; + public const string IDENTIFIER = 'geometry/scalepercent'; + /** + * @phpstan-param array{0?: int, 1?: int} $options width, height + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (count($options) < 2) { @@ -27,7 +31,7 @@ public function load(ImageInterface $image, array $options = []): ImageInterface $size = $image->getSize(); $origWidth = $size->getWidth(); $origHeight = $size->getHeight(); - list($widthPercent, $heightPercent) = $options; + [$widthPercent, $heightPercent] = $options; $targetWidth = ($origWidth * $widthPercent) / 100; $targetHeight = ($origHeight * $heightPercent) / 100; diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoader.php index 5b2777561b..69698680b8 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class ScaleWidthDownOnlyFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scalewidthdownonly'; + public const string IDENTIFIER = 'geometry/scalewidthdownonly'; + /** + * @phpstan-param array{0?: int} $options width + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (empty($options)) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoader.php index b15d374e4e..4da242d47b 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -16,8 +17,11 @@ */ class ScaleWidthFilterLoader extends FilterLoaderWrapped { - public const IDENTIFIER = 'geometry/scalewidth'; + public const string IDENTIFIER = 'geometry/scalewidth'; + /** + * @phpstan-param array{0?: int} $options width + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (empty($options)) { diff --git a/src/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoader.php b/src/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoader.php index 603a9d78d1..85e64b43d3 100644 --- a/src/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoader.php +++ b/src/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter\Loader; @@ -13,16 +14,18 @@ class SwirlFilterLoader implements LoaderInterface { - public const IDENTIFIER = 'filter/swirl'; + public const string IDENTIFIER = 'filter/swirl'; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterInterface */ - private $filter; + private FilterInterface $filter; public function __construct(FilterInterface $filter) { $this->filter = $filter; } + /** + * @phpstan-param array{0?: int|float} $options degrees + */ public function load(ImageInterface $image, array $options = []): ImageInterface { if (!empty($options)) { diff --git a/src/bundle/Core/Imagine/Filter/UnsupportedFilter.php b/src/bundle/Core/Imagine/Filter/UnsupportedFilter.php index 2b6cfd1f48..6914ffa119 100644 --- a/src/bundle/Core/Imagine/Filter/UnsupportedFilter.php +++ b/src/bundle/Core/Imagine/Filter/UnsupportedFilter.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Filter; @@ -15,7 +16,7 @@ class UnsupportedFilter extends AbstractFilter /** * @throws \Imagine\Exception\NotSupportedException */ - public function apply(ImageInterface $image) + public function apply(ImageInterface $image): never { throw new NotSupportedException('The filter is not supported by your current configuration.'); } diff --git a/src/bundle/Core/Imagine/ImageAsset/AliasGenerator.php b/src/bundle/Core/Imagine/ImageAsset/AliasGenerator.php index d021cf689a..c5df234f6e 100644 --- a/src/bundle/Core/Imagine/ImageAsset/AliasGenerator.php +++ b/src/bundle/Core/Imagine/ImageAsset/AliasGenerator.php @@ -18,24 +18,16 @@ use Ibexa\Core\FieldType\ImageAsset\Value as ImageAssetValue; /** - * Alias Generator Decorator allowing generate variations based on passed ImageAsset\Value. + * Alias Generator Decorator allowing to generate variations based on passed ImageAsset\Value. */ class AliasGenerator implements VariationHandler { - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $innerAliasGenerator; + private VariationHandler $innerAliasGenerator; - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; + private ContentService $contentService; - /** @var \Ibexa\Core\FieldType\ImageAsset\AssetMapper */ - private $assetMapper; + private AssetMapper $assetMapper; - /** - * @param \Ibexa\Contracts\Core\Variation\VariationHandler $innerAliasGenerator - * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService - * @param \Ibexa\Core\FieldType\ImageAsset\AssetMapper $assetMapper - */ public function __construct( VariationHandler $innerAliasGenerator, ContentService $contentService, @@ -46,9 +38,6 @@ public function __construct( $this->assetMapper = $assetMapper; } - /** - * {@inheritdoc} - */ public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation { if ($this->supportsValue($field->value)) { diff --git a/src/bundle/Core/Imagine/PlaceholderAliasGenerator.php b/src/bundle/Core/Imagine/PlaceholderAliasGenerator.php index b76111f32e..f3ad72209a 100644 --- a/src/bundle/Core/Imagine/PlaceholderAliasGenerator.php +++ b/src/bundle/Core/Imagine/PlaceholderAliasGenerator.php @@ -4,11 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException as APIInvalidArgumentException; -use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; +use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException as APINotFoundException; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; use Ibexa\Contracts\Core\Variation\Values\Variation; @@ -22,23 +23,18 @@ class PlaceholderAliasGenerator implements VariationHandler { - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $aliasGenerator; + private VariationHandler $aliasGenerator; - /** @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $ioResolver; + private ResolverInterface $ioResolver; - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $ioService; + private IOServiceInterface $ioService; - /** @var \Ibexa\Bundle\Core\Imagine\PlaceholderProvider|null */ - private $placeholderProvider; + private ?PlaceholderProvider $placeholderProvider = null; - /** @var array */ - private $placeholderOptions = []; + /** @var array */ + private array $placeholderOptions = []; - /** @var bool */ - private $verifyBinaryDataAvailability = false; + private bool $verifyBinaryDataAvailability = false; public function __construct( VariationHandler $aliasGenerator, @@ -51,15 +47,23 @@ public function __construct( } /** - * {@inheritdoc} + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ - public function getVariation(Field $field, VersionInfo $versionInfo, string $variationName, array $parameters = []): Variation - { + public function getVariation( + Field $field, + VersionInfo $versionInfo, + string $variationName, + array $parameters = [] + ): Variation { if ($this->placeholderProvider !== null) { /** @var \Ibexa\Core\FieldType\Image\Value $imageValue */ $imageValue = $field->value; if (!$this->supportsValue($imageValue)) { - throw new InvalidArgumentException("Value of Field with ID {$field->id} ($field->fieldDefIdentifier) cannot be used for generating an image placeholder."); + throw new InvalidArgumentException( + "Value of Field with ID {$field->id} ($field->fieldDefIdentifier) cannot be used for generating an image placeholder." + ); } if (!$this->isOriginalImageAvailable($imageValue)) { @@ -75,7 +79,10 @@ public function getVariation(Field $field, VersionInfo $versionInfo, string $var return $this->aliasGenerator->getVariation($field, $versionInfo, $variationName, $parameters); } - public function setPlaceholderProvider(PlaceholderProvider $provider, array $options = []) + /** + * @param array $options + */ + public function setPlaceholderProvider(PlaceholderProvider $provider, array $options = []): void { $this->placeholderProvider = $provider; $this->placeholderOptions = $options; @@ -84,9 +91,7 @@ public function setPlaceholderProvider(PlaceholderProvider $provider, array $opt /** * Enable/disable binary data availability verification. * - * If enabled then binary data storage will be used to check if original file exists. Required for DFS setup. - * - * @param bool $verifyBinaryDataAvailability + * If enabled, then binary data storage will be used to check if original file exists. Required for DFS setup. */ public function setVerifyBinaryDataAvailability(bool $verifyBinaryDataAvailability): void { @@ -102,15 +107,15 @@ private function isOriginalImageAvailable(ImageValue $imageValue): bool { try { $this->ioResolver->resolve($imageValue->id, IORepositoryResolver::VARIATION_ORIGINAL); - } catch (NotResolvableException $e) { + } catch (NotResolvableException) { return false; } if ($this->verifyBinaryDataAvailability) { try { - // Try to open input stream to original file + // Try to open input stream to an original file $this->ioService->getFileInputStream($this->ioService->loadBinaryFile($imageValue->id)); - } catch (NotFoundException | APIInvalidArgumentException $e) { + } catch (APINotFoundException | APIInvalidArgumentException) { return false; } } diff --git a/src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php b/src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php index a8a3b6d894..ac52b733b9 100644 --- a/src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php +++ b/src/bundle/Core/Imagine/PlaceholderAliasGeneratorConfigurator.php @@ -4,33 +4,29 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; -class PlaceholderAliasGeneratorConfigurator +final readonly class PlaceholderAliasGeneratorConfigurator { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; - - /** @var \Ibexa\Bundle\Core\Imagine\PlaceholderProviderRegistry */ - private $providerRegistry; - - /** @var array */ - private $providersConfig; - + /** + * @phpstan-param array, + * verify_binary_data_availability?: bool + * }> $providersConfig + */ public function __construct( - ConfigResolverInterface $configResolver, - PlaceholderProviderRegistry $providerRegistry, - array $providersConfig + private ConfigResolverInterface $configResolver, + private PlaceholderProviderRegistry $providerRegistry, + private array $providersConfig ) { - $this->configResolver = $configResolver; - $this->providerRegistry = $providerRegistry; - $this->providersConfig = $providersConfig; } - public function configure(PlaceholderAliasGenerator $generator) + public function configure(PlaceholderAliasGenerator $generator): void { $binaryHandlerName = $this->configResolver->getParameter('io.binarydata_handler'); diff --git a/src/bundle/Core/Imagine/PlaceholderProvider.php b/src/bundle/Core/Imagine/PlaceholderProvider.php index 8a78a6ea24..9671ed32f5 100644 --- a/src/bundle/Core/Imagine/PlaceholderProvider.php +++ b/src/bundle/Core/Imagine/PlaceholderProvider.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; @@ -14,8 +15,7 @@ interface PlaceholderProvider /** * Provides a placeholder image path for a given Image FieldType value. * - * @param \Ibexa\Core\FieldType\Image\Value $value - * @param array $options + * @param array $options * * @return string Path to placeholder */ diff --git a/src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php b/src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php index ca397bcd99..78e9effe60 100644 --- a/src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php +++ b/src/bundle/Core/Imagine/PlaceholderProvider/GenericProvider.php @@ -4,33 +4,26 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\PlaceholderProvider; use Ibexa\Bundle\Core\Imagine\PlaceholderProvider; use Ibexa\Core\FieldType\Image\Value as ImageValue; -use Imagine\Image as Image; +use Imagine\Image; +use Imagine\Image\AbstractFont; use Imagine\Image\ImagineInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class GenericProvider implements PlaceholderProvider { - /** @var \Imagine\Image\ImagineInterface */ - private $imagine; - - /** - * GenericProvider constructor. - * - * @param \Imagine\Image\ImagineInterface $imagine - */ + private ImagineInterface $imagine; + public function __construct(ImagineInterface $imagine) { $this->imagine = $imagine; } - /** - * {@inheritdoc} - */ public function getPlaceholder(ImageValue $value, array $options = []): string { $options = $this->resolveOptions($options); @@ -40,8 +33,12 @@ public function getPlaceholder(ImageValue $value, array $options = []): string $foreground = $palette->color($options['foreground']); $secondary = $palette->color($options['secondary']); - $size = new Image\Box($value->width, $value->height); + $size = new Image\Box($value->width ?? 0, $value->height ?? 0); $font = $this->imagine->font($options['fontpath'], $options['fontsize'], $foreground); + if (!$font instanceof AbstractFont) { + throw new \LogicException("Font {$options['fontpath']} is not an instance of AbstractFont"); + } + $text = $this->getPlaceholderText($options['text'], $value); $center = new Image\Point\Center($size); @@ -54,13 +51,13 @@ public function getPlaceholder(ImageValue $value, array $options = []): string $image = $this->imagine->create($size, $background); $image->draw()->line( new Image\Point(0, 0), - new Image\Point($value->width, $value->height), + new Image\Point($value->width ?? 0, $value->height ?? 0), $secondary ); $image->draw()->line( - new Image\Point($value->width, 0), - new Image\Point(0, $value->height), + new Image\Point($value->width ?? 0, 0), + new Image\Point(0, $value->height ?? 0), $secondary ); diff --git a/src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php b/src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php index 9ec16b2c5d..653f0fb03e 100644 --- a/src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php +++ b/src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\PlaceholderProvider; @@ -17,9 +18,6 @@ */ class RemoteProvider implements PlaceholderProvider { - /** - * {@inheritdoc} - */ public function getPlaceholder(ImageValue $value, array $options = []): string { $options = $this->resolveOptions($options); @@ -61,6 +59,9 @@ private function getTemporaryPath(): string return stream_get_meta_data(tmpfile())['uri']; } + /** + * @param array $options + */ private function resolveOptions(array $options): array { $resolver = new OptionsResolver(); diff --git a/src/bundle/Core/Imagine/PlaceholderProviderRegistry.php b/src/bundle/Core/Imagine/PlaceholderProviderRegistry.php index 3ef89d4ff8..be2a8d5e63 100644 --- a/src/bundle/Core/Imagine/PlaceholderProviderRegistry.php +++ b/src/bundle/Core/Imagine/PlaceholderProviderRegistry.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine; @@ -11,20 +12,14 @@ class PlaceholderProviderRegistry { - /** @var \Ibexa\Bundle\Core\Imagine\PlaceholderProvider */ - private $providers; - /** - * PlaceholderProviderRegistry constructor. - * - * @param array $providers + * @param array $providers */ - public function __construct(array $providers = []) + public function __construct(private array $providers = []) { - $this->providers = $providers; } - public function addProvider(string $type, PlaceholderProvider $provider) + public function addProvider(string $type, PlaceholderProvider $provider): void { $this->providers[$type] = $provider; } diff --git a/src/bundle/Core/Imagine/Variation/ImagineAwareAliasGenerator.php b/src/bundle/Core/Imagine/Variation/ImagineAwareAliasGenerator.php index 05cb472a90..b0464e1eff 100644 --- a/src/bundle/Core/Imagine/Variation/ImagineAwareAliasGenerator.php +++ b/src/bundle/Core/Imagine/Variation/ImagineAwareAliasGenerator.php @@ -4,17 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\Variation; use Ibexa\Bundle\Core\Imagine\IORepositoryResolver; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; +use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Contracts\Core\Variation\Values\ImageVariation; use Ibexa\Contracts\Core\Variation\Values\Variation; use Ibexa\Contracts\Core\Variation\VariationHandler; use Ibexa\Contracts\Core\Variation\VariationPathGenerator; use Ibexa\Core\IO\IOServiceInterface; +use Ibexa\Core\IO\Values\BinaryFile; use Imagine\Image\ImagineInterface; /** @@ -23,20 +26,15 @@ */ class ImagineAwareAliasGenerator implements VariationHandler { - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $aliasGenerator; + private VariationHandler $aliasGenerator; - /** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator */ - private $variationPathGenerator; + private VariationPathGenerator $variationPathGenerator; - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $ioService; + private IOServiceInterface $ioService; - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** @var \Imagine\Image\ImagineInterface */ - private $imagine; + private ImagineInterface $imagine; public function __construct( VariationHandler $aliasGenerator, @@ -50,14 +48,6 @@ public function __construct( $this->imagine = $imagine; } - /** - * Returns a Variation object, ensuring proper image dimensions. - * - * {@inheritdoc} - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ public function getVariation( Field $field, VersionInfo $versionInfo, @@ -97,17 +87,12 @@ public function getVariation( } /** - * Get image variation filesystem path. - * - * @param string $originalPath - * @param string $variationName - * - * @return \Ibexa\Core\IO\Values\BinaryFile + * Get an image variation filesystem path. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - private function getVariationBinaryFile($originalPath, $variationName) + private function getVariationBinaryFile(string $originalPath, string $variationName): BinaryFile { if ($variationName !== IORepositoryResolver::VARIATION_ORIGINAL) { $variationPath = $this->variationPathGenerator->getVariationPath( diff --git a/src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php b/src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php index a2d16900da..f2fe65823f 100644 --- a/src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php +++ b/src/bundle/Core/Imagine/VariationPurger/IOVariationPurger.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; @@ -11,6 +12,8 @@ use Ibexa\Contracts\Core\Variation\VariationPurger; use Ibexa\Core\IO\IOServiceInterface; use Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; /** @@ -18,22 +21,17 @@ * * Depends on aliases being stored in their own folder, with each alias folder mirroring the original files structure. */ -class IOVariationPurger implements VariationPurger +class IOVariationPurger implements VariationPurger, LoggerAwareInterface { - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $io; + use LoggerAwareTrait; - /** @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */ - private $cache; + private IOServiceInterface $io; - /** @var \Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface */ - private $cacheIdentifierGenerator; + private TagAwareAdapterInterface $cache; - /** @var \Ibexa\Bundle\Core\Imagine\Cache\AliasGeneratorDecorator */ - private $aliasGeneratorDecorator; + private CacheIdentifierGeneratorInterface $cacheIdentifierGenerator; - /** @var \Psr\Log\LoggerInterface */ - private $logger; + private AliasGeneratorDecorator $aliasGeneratorDecorator; public function __construct( IOServiceInterface $io, @@ -47,14 +45,6 @@ public function __construct( $this->aliasGeneratorDecorator = $aliasGeneratorDecorator; } - /** - * @param \Psr\Log\LoggerInterface $logger - */ - public function setLogger($logger) - { - $this->logger = $logger; - } - public function purge(array $aliasNames): void { $variationNameTag = $this->aliasGeneratorDecorator->getVariationNameTag(); diff --git a/src/bundle/Core/Imagine/VariationPurger/ImageFileList.php b/src/bundle/Core/Imagine/VariationPurger/ImageFileList.php index 4f574a6d0c..17ebc9d78e 100644 --- a/src/bundle/Core/Imagine/VariationPurger/ImageFileList.php +++ b/src/bundle/Core/Imagine/VariationPurger/ImageFileList.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; @@ -12,6 +13,8 @@ /** * Iterates over BinaryFile id entries for original images. + * + * @extends \Iterator */ interface ImageFileList extends Countable, Iterator { diff --git a/src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php b/src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php index b06e93e63f..debfc38750 100644 --- a/src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php +++ b/src/bundle/Core/Imagine/VariationPurger/ImageFileRowReader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; @@ -17,19 +18,17 @@ interface ImageFileRowReader * * Can for instance be used to create and execute a database query. */ - public function init(); + public function init(): void; /** * Returns the next row from the data source. - * - * @return mixed|null The row's value, or null if none. */ - public function getRow(); + public function getRow(): ?string; /** * Returns the total row count. * - * @return int + * @phpstan-return int<0, max> */ - public function getCount(); + public function getCount(): int; } diff --git a/src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php b/src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php index f9f1793bb4..b069a794b4 100644 --- a/src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php +++ b/src/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurger.php @@ -4,13 +4,15 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; use Ibexa\Contracts\Core\Variation\VariationPathGenerator; use Ibexa\Contracts\Core\Variation\VariationPurger; use Ibexa\Core\IO\IOServiceInterface; -use Iterator; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; /** * Purges image aliases based on image files referenced by the Image FieldType. @@ -18,25 +20,15 @@ * It uses an ImageFileList iterator that lists original images, and the variationPathGenerator + IOService to remove * aliases if they exist. */ -class ImageFileVariationPurger implements VariationPurger +class ImageFileVariationPurger implements VariationPurger, LoggerAwareInterface { - /** @var ImageFileList */ - private $imageFileList; + use LoggerAwareTrait; - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $ioService; - - /** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator */ - private $variationPathGenerator; - - /** @var \Psr\Log\LoggerInterface */ - private $logger; - - public function __construct(Iterator $imageFileList, IOServiceInterface $ioService, VariationPathGenerator $variationPathGenerator) - { - $this->imageFileList = $imageFileList; - $this->ioService = $ioService; - $this->variationPathGenerator = $variationPathGenerator; + public function __construct( + private readonly ImageFileList $imageFileList, + private readonly IOServiceInterface $ioService, + private readonly VariationPathGenerator $variationPathGenerator + ) { } public function purge(array $aliasNames): void @@ -56,12 +48,4 @@ public function purge(array $aliasNames): void } } } - - /** - * @param \Psr\Log\LoggerInterface $logger - */ - public function setLogger($logger) - { - $this->logger = $logger; - } } diff --git a/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileList.php b/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileList.php index e58fb76693..1a856e4972 100644 --- a/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileList.php +++ b/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileList.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; @@ -19,43 +20,25 @@ class LegacyStorageImageFileList implements ImageFileList { /** * Last fetched item. - * - * @var mixed */ - private $item; + private ?string $item; /** * Iteration cursor on $statement. * * @var int */ - private $cursor; - - /** - * Used to get ezimagefile rows. - * - * @var \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileRowReader - */ - private $rowReader; - - /** @var \Ibexa\Core\IO\IOConfigProvider */ - private $ioConfigResolver; - - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private int $cursor; public function __construct( - ImageFileRowReader $rowReader, - IOConfigProvider $ioConfigResolver, - ConfigResolverInterface $configResolver + private readonly ImageFileRowReader $rowReader, + private readonly IOConfigProvider $ioConfigResolver, + private readonly ConfigResolverInterface $configResolver ) { - $this->ioConfigResolver = $ioConfigResolver; - $this->rowReader = $rowReader; - $this->configResolver = $configResolver; } #[\ReturnTypeWillChange] - public function current(): mixed + public function current(): ?string { return $this->item; } @@ -96,9 +79,13 @@ private function fetchRow(): void $storageDir = $this->ioConfigResolver->getLegacyUrlPrefix(); $prefix = $storageDir . '/' . $this->configResolver->getParameter('image.published_images_dir'); ++$this->cursor; - $imageId = $this->rowReader->getRow(); + $this->item = $this->rowReader->getRow(); + if ($this->item === null) { + return; + } - if (0 === strncmp((string)$imageId, $prefix, strlen($prefix))) { + $imageId = $this->item; + if (0 === strncmp($imageId, $prefix, strlen($prefix))) { $imageId = ltrim(substr($imageId, strlen($prefix)), '/'); } diff --git a/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileRowReader.php b/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileRowReader.php index 4354a168e7..5184d7b890 100644 --- a/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileRowReader.php +++ b/src/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileRowReader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Imagine\VariationPurger; @@ -24,28 +25,40 @@ public function __construct(Connection $connection) $this->result = null; } - public function init() + /** + * @throws \Doctrine\DBAL\Exception + */ + public function init(): void { $selectQuery = $this->connection->createQueryBuilder(); $selectQuery->select('filepath')->from(DoctrineStorage::IMAGE_FILE_TABLE); $this->result = $selectQuery->executeQuery(); } - public function getRow() + /** + * @throws \Doctrine\DBAL\Exception + */ + public function getRow(): ?string { if ($this->result === null) { throw new LogicException('Uninitialized reader. You must call init() before getRow()'); } - return $this->result->fetchOne(); + $filePath = $this->result->fetchOne(); + + return $filePath ?: null; } - public function getCount() + /** + * @throws \Doctrine\DBAL\Exception + */ + public function getCount(): int { if ($this->result === null) { throw new LogicException('Uninitialized reader. You must call init() before getRow()'); } + /** @phpstan-var int<0, max> */ return $this->result->rowCount(); } } diff --git a/src/bundle/Core/Resources/config/fieldtype_services.yml b/src/bundle/Core/Resources/config/fieldtype_services.yml index 397675965d..ab3ea27eb7 100644 --- a/src/bundle/Core/Resources/config/fieldtype_services.yml +++ b/src/bundle/Core/Resources/config/fieldtype_services.yml @@ -44,12 +44,11 @@ services: # Image Ibexa\Core\FieldType\Image\IO\Legacy: - class: Ibexa\Core\FieldType\Image\IO\Legacy arguments: - - '@ibexa.field_type.ibexa_image.io_service.published' - - '@ibexa.field_type.ibexa_image.io_service.draft' - - '@Ibexa\Core\FieldType\Image\IO\OptionsProvider' - # Required by ezpublish.core.io.stream_file_listener. Request listeners are initialized very early. + $publishedIOService: '@ibexa.field_type.ibexa_image.io_service.published' + $draftIOService: '@ibexa.field_type.ibexa_image.io_service.draft' + $optionsProvider: '@Ibexa\Core\FieldType\Image\IO\OptionsProvider' + # Required by Ibexa\Bundle\IO\EventListener\StreamFileListener. Request listeners are initialized very early. lazy: true Ibexa\Core\FieldType\Image\IO\OptionsProvider: diff --git a/src/bundle/Core/Resources/config/image.yml b/src/bundle/Core/Resources/config/image.yml index c657212c7e..af9850bc05 100644 --- a/src/bundle/Core/Resources/config/image.yml +++ b/src/bundle/Core/Resources/config/image.yml @@ -47,12 +47,11 @@ services: - { name: liip_imagine.cache.resolver, resolver: ibexa } Ibexa\Bundle\Core\Imagine\Cache\ResolverFactory: - class: Ibexa\Bundle\Core\Imagine\Cache\ResolverFactory arguments: - - '@ibexa.config.resolver' - - '@ibexa.image_alias.imagine.cache_resolver_decorator.inner' - - 'Ibexa\Bundle\Core\Imagine\Cache\Resolver\ProxyResolver' - - 'Ibexa\Bundle\Core\Imagine\Cache\Resolver\RelativeResolver' + $configResolver: '@ibexa.config.resolver' + $resolver: '@ibexa.image_alias.imagine.cache_resolver_decorator.inner' + $proxyResolverClass: 'Ibexa\Bundle\Core\Imagine\Cache\Resolver\ProxyResolver' + $relativeResolverClass: 'Ibexa\Bundle\Core\Imagine\Cache\Resolver\RelativeResolver' lazy: true ibexa.image_alias.imagine.cache_resolver_decorator: @@ -236,24 +235,19 @@ services: alias: Ibexa\Bundle\Core\Imagine\VariationPurger\IOVariationPurger Ibexa\Bundle\Core\Imagine\VariationPurger\IOVariationPurger: - class: Ibexa\Bundle\Core\Imagine\VariationPurger\IOVariationPurger + autoconfigure: true arguments: - - '@Ibexa\Core\FieldType\Image\IO\Legacy' - - '@ibexa.cache_pool' - - '@Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface' - - '@Ibexa\Bundle\Core\Imagine\Cache\AliasGeneratorDecorator' - - '@Ibexa\Bundle\Core\Imagine\VariationPathGenerator\AliasDirectoryVariationPathGenerator' - calls: - - [setLogger, ["@?logger"]] + $io: '@Ibexa\Core\FieldType\Image\IO\Legacy' + $cache: '@ibexa.cache_pool' + $cacheIdentifierGenerator: '@Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface' + $aliasGeneratorDecorator: '@Ibexa\Bundle\Core\Imagine\Cache\AliasGeneratorDecorator' Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileVariationPurger: - class: Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileVariationPurger + autoconfigure: true arguments: - - '@Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList' - - '@Ibexa\Core\FieldType\Image\IO\Legacy' - - '@Ibexa\Bundle\Core\Imagine\VariationPathGenerator\OriginalDirectoryVariationPathGenerator' - calls: - - [setLogger, ["@?logger"]] + $imageFileList: '@Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList' + $ioService: '@Ibexa\Core\FieldType\Image\IO\Legacy' + $variationPathGenerator: '@Ibexa\Bundle\Core\Imagine\VariationPathGenerator\OriginalDirectoryVariationPathGenerator' Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList: class: Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList diff --git a/src/bundle/Core/Variation/VariationHandlerResolver.php b/src/bundle/Core/Variation/VariationHandlerResolver.php index 0e42561fb6..01b45a9e3c 100644 --- a/src/bundle/Core/Variation/VariationHandlerResolver.php +++ b/src/bundle/Core/Variation/VariationHandlerResolver.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\Core\Variation; diff --git a/src/bundle/IO/ApiLoader/HandlerRegistry.php b/src/bundle/IO/ApiLoader/HandlerRegistry.php index 76aa227d72..03361270a0 100644 --- a/src/bundle/IO/ApiLoader/HandlerRegistry.php +++ b/src/bundle/IO/ApiLoader/HandlerRegistry.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\ApiLoader; @@ -11,29 +12,34 @@ /** * Registry of IO handlers, given an alias. + * + * @template THandlerType of object + * + * @phpstan-type TIOHandlersMap array */ class HandlerRegistry { /** - * Map of handler id to handler service id. + * Map of a handler id to a handler service instance. * - * @var array + * @phpstan-var TIOHandlersMap */ - private $handlersMap = []; + private array $handlersMap = []; - public function setHandlersMap($handlersMap) + /** + * @phpstan-param TIOHandlersMap $handlersMap + */ + public function setHandlersMap(array $handlersMap): void { $this->handlersMap = $handlersMap; } /** - * @param string $handlerName - * - * @return object an instance of the requested handler - * * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException If the requested handler doesn't exist + * + * @phpstan-return THandlerType */ - public function getConfiguredHandler($handlerName) + public function getConfiguredHandler(string $handlerName): object { if (!isset($this->handlersMap[$handlerName])) { throw new InvalidConfigurationException("Unknown handler $handlerName"); diff --git a/src/bundle/IO/BinaryStreamResponse.php b/src/bundle/IO/BinaryStreamResponse.php index 447cde477c..3365bb8456 100644 --- a/src/bundle/IO/BinaryStreamResponse.php +++ b/src/bundle/IO/BinaryStreamResponse.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO; diff --git a/src/bundle/IO/Command/MigrateFilesCommand.php b/src/bundle/IO/Command/MigrateFilesCommand.php index defba863f7..a973c65618 100644 --- a/src/bundle/IO/Command/MigrateFilesCommand.php +++ b/src/bundle/IO/Command/MigrateFilesCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -23,29 +24,21 @@ )] final class MigrateFilesCommand extends Command { - /** @var mixed Configuration for metadata handlers */ - private $configuredMetadataHandlers; - - /** @var mixed Configuration for binary data handlers */ - private $configuredBinarydataHandlers; - - /** @var \Ibexa\Bundle\IO\Migration\FileListerRegistry */ - private $fileListerRegistry; - /** @var \Ibexa\Bundle\IO\Migration\FileListerInterface[] */ - private $fileListers; - - /** @var \Ibexa\Bundle\IO\Migration\FileMigratorInterface */ - private $fileMigrator; + private array $fileListers = []; + /** + * @param array> $configuredMetadataHandlers + * @param array> $configuredBinarydataHandlers + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + */ public function __construct( - array $configuredMetadataHandlers, - array $configuredBinarydataHandlers, - FileListerRegistry $fileListerRegistry, - FileMigratorInterface $fileMigrator + private array $configuredMetadataHandlers, + private array $configuredBinarydataHandlers, + private readonly FileListerRegistry $fileListerRegistry, + private readonly FileMigratorInterface $fileMigrator ) { - $this->configuredMetadataHandlers = $configuredMetadataHandlers; - $this->configuredBinarydataHandlers = $configuredBinarydataHandlers; if (!array_key_exists('default', $this->configuredMetadataHandlers)) { $this->configuredMetadataHandlers['default'] = []; } @@ -53,9 +46,6 @@ public function __construct( $this->configuredBinarydataHandlers['default'] = []; } - $this->fileListerRegistry = $fileListerRegistry; - $this->fileMigrator = $fileMigrator; - foreach ($this->fileListerRegistry->getIdentifiers() as $fileListerIdentifier) { $this->fileListers[] = $this->fileListerRegistry->getItem($fileListerIdentifier); } @@ -152,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); $output->writeln([ - 'Total number of files to migrate: ' . ($totalCount === null ? 'unknown' : $totalCount), + 'Total number of files to migrate: ' . $totalCount, 'This number does not include image variations, but they will also be migrated.', '', ]); @@ -164,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if (!$input->getOption('no-interaction')) { - $helper = $this->getHelper('question'); + $helper = new QuestionHelper(); $question = new ConfirmationQuestion( 'Are you sure you want to proceed? ', false @@ -192,7 +182,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * * @param \Symfony\Component\Console\Output\OutputInterface $output */ - protected function outputConfiguredHandlers(OutputInterface $output) + protected function outputConfiguredHandlers(OutputInterface $output): void { $output->writeln( 'Configured metadata handlers: ' . implode(', ', array_keys($this->configuredMetadataHandlers)) @@ -205,15 +195,12 @@ protected function outputConfiguredHandlers(OutputInterface $output) /** * Verify that the handler options have been set to meaningful values. * - * @param mixed $fromHandlers - * @param mixed $toHandlers - * @param \Symfony\Component\Console\Output\OutputInterface $output - * - * @return bool + * @param string[] $fromHandlers + * @param string[] $toHandlers */ protected function validateHandlerOptions( - $fromHandlers, - $toHandlers, + array $fromHandlers, + array $toHandlers, OutputInterface $output ): bool { foreach (['From' => $fromHandlers, 'To' => $toHandlers] as $direction => $handlers) { @@ -228,9 +215,10 @@ protected function validateHandlerOptions( } foreach (['meta' => $handlers[0], 'binary' => $handlers[1]] as $fileDataType => $handler) { - if (!in_array($handler, array_keys( + $handlers = array_keys( $fileDataType === 'meta' ? $this->configuredMetadataHandlers : $this->configuredBinarydataHandlers - ))) { + ); + if (!in_array($handler, $handlers, true)) { $output->writeln("$direction $fileDataType data handler '$handler' is not configured."); $this->outputConfiguredHandlers($output); @@ -252,18 +240,16 @@ protected function validateHandlerOptions( * Migrate files. * * @param int|null $totalFileCount Total count of files, null if unknown - * @param int $bulkCount Number of files to process in each batch - * @param bool $dryRun - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param int|null $bulkCount Number of files to process in each batch */ protected function migrateFiles( - $totalFileCount, - $bulkCount, - $dryRun, + ?int $totalFileCount, + ?int $bulkCount, + bool $dryRun, OutputInterface $output - ) { - $progress = new ProgressBar($output, $totalFileCount); - if ($totalFileCount) { + ): void { + $progress = new ProgressBar($output, $totalFileCount ?? 0); + if (null !== $totalFileCount) { $progress->setFormat("%message%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%"); } else { $progress->setFormat("%message%\n %current% [%bar%] %elapsed:6s% %memory:6s%"); @@ -298,7 +284,7 @@ protected function migrateFiles( $updateFrequency = (int)($updateFrequency / 2); $progress->setRedrawFrequency($updateFrequency); } elseif ($newTimestamp - $timestamp < 0.1 && $updateFrequency < 10000) { - $updateFrequency = $updateFrequency * 2; + $updateFrequency *= 2; $progress->setRedrawFrequency($updateFrequency); } $timestamp = $newTimestamp; diff --git a/src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php b/src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php index d1934ac88e..c8b1747eed 100644 --- a/src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php +++ b/src/bundle/IO/DependencyInjection/Compiler/IOConfigurationPass.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection\Compiler; @@ -14,62 +15,53 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; /** - * @todo Refactor into two passes, since they're very very close. + * @internal + * + * @phpstan-import-type THandlerConfigurationFactoryList from \Ibexa\Bundle\IO\DependencyInjection\Configuration */ -class IOConfigurationPass implements CompilerPassInterface +final readonly class IOConfigurationPass implements CompilerPassInterface { - /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject */ - private $metadataHandlerFactories; - - /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject */ - private $binarydataHandlerFactories; - + /** + * @phpstan-param THandlerConfigurationFactoryList $metadataHandlerFactories + * @phpstan-param THandlerConfigurationFactoryList $binarydataHandlerFactories + */ public function __construct( - ArrayObject $metadataHandlerFactories = null, - ArrayObject $binarydataHandlerFactories = null + private ArrayObject $metadataHandlerFactories, + private ArrayObject $binarydataHandlerFactories ) { - $this->metadataHandlerFactories = $metadataHandlerFactories; - $this->binarydataHandlerFactories = $binarydataHandlerFactories; } public function process(ContainerBuilder $container): void { - $ioMetadataHandlers = $container->hasParameter('ibexa.io.metadata_handlers') ? - $container->getParameter('ibexa.io.metadata_handlers') : - []; - $this->processHandlers( + $this->processHandlerFactories( $container, - $container->getDefinition('ibexa.core.io.metadata_handler.registry'), - $ioMetadataHandlers, $this->metadataHandlerFactories, + 'ibexa.io.metadata_handlers', + 'ibexa.core.io.metadata_handler.registry', 'ibexa.core.io.metadata_handler.flysystem.default' ); - $ioBinarydataHandlers = $container->hasParameter('ibexa.io.binarydata_handlers') ? - $container->getParameter('ibexa.io.binarydata_handlers') : - []; - $this->processHandlers( + $this->processHandlerFactories( $container, - $container->getDefinition('ibexa.core.io.binarydata_handler.registry'), - $ioBinarydataHandlers, $this->binarydataHandlerFactories, + 'ibexa.io.binarydata_handlers', + 'ibexa.core.io.binarydata_handler.registry', 'ibexa.core.io.binarydata_handler.flysystem.default' ); - - // Unset parameters that are no longer required ? } /** - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @param \Symfony\Component\DependencyInjection\Definition $factory The factory service that should receive the list of handlers - * @param array $configuredHandlers Handlers configuration declared via semantic config - * @param \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject $factories Map of alias => handler service id + * @param array $configuredHandlers Handlers configuration declared via semantic config * @param string $defaultHandler default handler id + * + * @phpstan-param THandlerConfigurationFactoryList $factories Map of alias => handler service id */ - protected function processHandlers( + private function processHandlers( ContainerBuilder $container, Definition $factory, array $configuredHandlers, @@ -97,10 +89,9 @@ protected function processHandlers( /** * Returns from $factories the factory for handler $type. * - * @param \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject $factories - * @param string $type + * @phpstan-param THandlerConfigurationFactoryList $factories */ - protected function getFactory(ArrayObject $factories, string $type): ConfigurationFactory + private function getFactory(ArrayObject $factories, string $type): ConfigurationFactory { if (!isset($factories[$type])) { throw new InvalidConfigurationException("Unknown handler type $type"); @@ -108,4 +99,36 @@ protected function getFactory(ArrayObject $factories, string $type): Configurati return $factories[$type]; } + + /** + * @phpstan-param THandlerConfigurationFactoryList $ioHandlerConfigurationFactories + */ + private function processHandlerFactories( + ContainerBuilder $container, + ArrayObject $ioHandlerConfigurationFactories, + string $handlerListParameterName, + string $registryServiceID, + string $defaultFlysystemServiceID + ): void { + $ioHandlerList = $container->hasParameter($handlerListParameterName) ? + $container->getParameter($handlerListParameterName) : + []; + if (!is_array($ioHandlerList)) { + throw new InvalidArgumentException( + sprintf( + 'Parameter \'%s\' must be an array, %s given', + $handlerListParameterName, + get_debug_type($ioHandlerList) + ) + ); + } + + $this->processHandlers( + $container, + $container->getDefinition($registryServiceID), + $ioHandlerList, + $ioHandlerConfigurationFactories, + $defaultFlysystemServiceID + ); + } } diff --git a/src/bundle/IO/DependencyInjection/Compiler/MigrationFileListerPass.php b/src/bundle/IO/DependencyInjection/Compiler/MigrationFileListerPass.php index ddf0c89849..d84353f209 100644 --- a/src/bundle/IO/DependencyInjection/Compiler/MigrationFileListerPass.php +++ b/src/bundle/IO/DependencyInjection/Compiler/MigrationFileListerPass.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection\Compiler; diff --git a/src/bundle/IO/DependencyInjection/Configuration.php b/src/bundle/IO/DependencyInjection/Configuration.php index d3f4e09a85..9251829e66 100644 --- a/src/bundle/IO/DependencyInjection/Configuration.php +++ b/src/bundle/IO/DependencyInjection/Configuration.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection; @@ -11,27 +12,43 @@ use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\DependencyInjection\Exception\LogicException; +/** + * @internal + * + * @phpstan-type THandlerConfigurationFactoryList \ArrayObject + */ class Configuration implements ConfigurationInterface { - /** @var ConfigurationFactory[]|\ArrayObject */ - private $metadataHandlerFactories = []; + /** @phpstan-var THandlerConfigurationFactoryList */ + private ArrayObject $metadataHandlerFactories; - /** @var ConfigurationFactory[]|\ArrayObject */ - private $binarydataHandlerFactories = []; + /** @phpstan-var THandlerConfigurationFactoryList */ + private ArrayObject $binarydataHandlerFactories; - public function setMetadataHandlerFactories(ArrayObject $factories) + /** + * @phpstan-param THandlerConfigurationFactoryList $factories + */ + public function setMetadataHandlerFactories(ArrayObject $factories): void { $this->metadataHandlerFactories = $factories; } - public function setBinarydataHandlerFactories(ArrayObject $factories) + /** + * @phpstan-param THandlerConfigurationFactoryList $factories + */ + public function setBinarydataHandlerFactories(ArrayObject $factories): void { $this->binarydataHandlerFactories = $factories; } public function getConfigTreeBuilder(): TreeBuilder { + if (!isset($this->binarydataHandlerFactories, $this->metadataHandlerFactories)) { + throw new LogicException('IO configuration handler factories need to be initialized'); + } + $treeBuilder = new TreeBuilder(IbexaIOExtension::EXTENSION_NAME); $rootNode = $treeBuilder->getRootNode(); @@ -55,12 +72,9 @@ public function getConfigTreeBuilder(): TreeBuilder } /** - * @param \Symfony\Component\Config\Definition\Builder\NodeDefinition $node - * @param string $name - * @param string $info block info line - * @param ConfigurationFactory[]|\ArrayObject $factories + * @phpstan-param THandlerConfigurationFactoryList $factories */ - private function addHandlersSection(NodeDefinition $node, $name, $info, ArrayObject $factories) + private function addHandlersSection(NodeDefinition $node, string $name, string $info, ArrayObject $factories): void { $handlersNodeBuilder = $node ->children() @@ -71,8 +85,8 @@ private function addHandlersSection(NodeDefinition $node, $name, $info, ArrayObj ->performNoDeepMerging() ->children(); - foreach ($factories as $name => $factory) { - $factoryNode = $handlersNodeBuilder->arrayNode($name)->canBeUnset(); + foreach ($factories as $factoryName => $factory) { + $factoryNode = $handlersNodeBuilder->arrayNode($factoryName)->canBeUnset(); $factory->addConfiguration($factoryNode); } } diff --git a/src/bundle/IO/DependencyInjection/ConfigurationFactory.php b/src/bundle/IO/DependencyInjection/ConfigurationFactory.php index c68944abad..89e432f9ff 100644 --- a/src/bundle/IO/DependencyInjection/ConfigurationFactory.php +++ b/src/bundle/IO/DependencyInjection/ConfigurationFactory.php @@ -27,24 +27,22 @@ interface ConfigurationFactory * Example: * ```php * $node - * ->info( 'my info' )->example( 'an example' ) + * ->info('my info')->example('an example') * ->children() - * ->scalarNode( 'an_argument' )->info( 'This is an argument' ) + * ->scalarNode('an_argument')->info('This is an argument') * ->end(); * ``` * * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node The handler's configuration node. */ - public function addConfiguration(ArrayNodeDefinition $node); + public function addConfiguration(ArrayNodeDefinition $node): void; /** * Returns the ID of the base, abstract service used to create the handlers. * * It will be used as the base name for instances of this handler, and as the parent of the instances' services. - * - * @return string */ - public function getParentServiceId(); + public function getParentServiceId(): string; /** * Configure the handler service based on the configuration. @@ -52,10 +50,7 @@ public function getParentServiceId(); * Arguments or calls can be added to the $serviceDefinition, extra services or parameters can be added to the * container. * - * Note: if the factory implements ContainerAwareInterface, the ContainerBuilder will be made available as $this->container. - * - * @param \Symfony\Component\DependencyInjection\Definition $serviceDefinition - * @param array $config + * @param array $config */ - public function configureHandler(ContainerBuilder $container, ServiceDefinition $serviceDefinition, array $config); + public function configureHandler(ContainerBuilder $container, ServiceDefinition $serviceDefinition, array $config): void; } diff --git a/src/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/Flysystem.php b/src/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/Flysystem.php index 617de5a2de..02db9eb9b7 100644 --- a/src/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/Flysystem.php +++ b/src/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/Flysystem.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\BinarydataHandler; diff --git a/src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php b/src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php index ecf4d39901..fbfe8dd604 100644 --- a/src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php +++ b/src/bundle/IO/DependencyInjection/ConfigurationFactory/Flysystem.php @@ -19,11 +19,11 @@ /** * Configuration factory for the flysystem metadata and binarydata handlers. * - * Binarydata & metadata are identical, except for the parent service. + * Binary data & metadata are identical, except for the parent service. */ abstract class Flysystem implements ConfigurationFactory { - public function addConfiguration(ArrayNodeDefinition $node) + public function addConfiguration(ArrayNodeDefinition $node): void { $node ->info( @@ -42,30 +42,21 @@ public function addConfiguration(ArrayNodeDefinition $node) ->end(); } - public function configureHandler(ContainerBuilder $container, ServiceDefinition $definition, array $config) + public function configureHandler(ContainerBuilder $container, ServiceDefinition $definition, array $config): void { $filesystemId = $this->createFilesystem($container, $config['name'], $config['adapter']); $definition->replaceArgument(0, new Reference($filesystemId)); } - /** - * Creates a flysystem filesystem $name service. - * - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container - * @param string $name filesystem name (nfs, local...) - * @param string $adapter adapter name - * - * @return string - */ - private function createFilesystem(ContainerBuilder $container, $name, $adapter): string + private function createFilesystem(ContainerBuilder $container, string $fileSystemName, string $adapterName): string { - $adapterId = sprintf('oneup_flysystem.%s_adapter', $adapter); + $adapterId = sprintf('oneup_flysystem.%s_adapter', $adapterName); // has either definition or alias if (!$container->has($adapterId)) { - throw new InvalidConfigurationException("Unknown flysystem adapter $adapter"); + throw new InvalidConfigurationException("Unknown flysystem adapter $adapterName"); } - $filesystemId = sprintf('ibexa.core.io.flysystem.%s_filesystem', $name); + $filesystemId = sprintf('ibexa.core.io.flysystem.%s_filesystem', $fileSystemName); $filesystemServiceDefinition = new ChildDefinition('ibexa.core.io.flysystem.base_filesystem'); $definition = $container->setDefinition( $filesystemId, diff --git a/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/Flysystem.php b/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/Flysystem.php index 3f9cfe6318..2e1ba8970a 100644 --- a/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/Flysystem.php +++ b/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/Flysystem.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler; diff --git a/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php b/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php index 9f23d91764..e470eadbb8 100644 --- a/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php +++ b/src/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSCluster.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler; @@ -20,12 +21,12 @@ public function getParentServiceId(): string return \Ibexa\Core\IO\IOMetadataHandler\LegacyDFSCluster::class; } - public function configureHandler(ContainerBuilder $container, ServiceDefinition $definition, array $config) + public function configureHandler(ContainerBuilder $container, ServiceDefinition $serviceDefinition, array $config): void { - $definition->replaceArgument(0, new Reference($config['connection'])); + $serviceDefinition->replaceArgument(0, new Reference($config['connection'])); } - public function addConfiguration(ArrayNodeDefinition $node) + public function addConfiguration(ArrayNodeDefinition $node): void { $node ->info( diff --git a/src/bundle/IO/EventListener/StreamFileListener.php b/src/bundle/IO/EventListener/StreamFileListener.php index 0a8a740c86..46bf463388 100644 --- a/src/bundle/IO/EventListener/StreamFileListener.php +++ b/src/bundle/IO/EventListener/StreamFileListener.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\EventListener; @@ -19,14 +20,14 @@ /** * Listens for IO files requests, and streams them. + * + * @internal */ class StreamFileListener implements EventSubscriberInterface { - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $ioService; + private IOServiceInterface $ioService; - /** @var \Ibexa\Core\IO\IOConfigProvider */ - private $ioConfigResolver; + private IOConfigProvider $ioConfigResolver; public function __construct(IOServiceInterface $ioService, IOConfigProvider $ioConfigResolver) { @@ -41,7 +42,11 @@ public static function getSubscribedEvents(): array ]; } - public function onKernelRequest(RequestEvent $event) + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public function onKernelRequest(RequestEvent $event): void { if ($event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { return; @@ -51,7 +56,7 @@ public function onKernelRequest(RequestEvent $event) $urlPrefix = $this->ioConfigResolver->getUrlPrefix(); $pathInfo = $request->getPathInfo(); - if (strpos($urlPrefix, '://') !== false) { + if (str_contains($urlPrefix, '://')) { $uri = $request->getSchemeAndHttpHost() . $pathInfo; } else { $uri = $pathInfo; @@ -76,14 +81,9 @@ public function onKernelRequest(RequestEvent $event) /** * Tests if $uri is an IO file uri root. - * - * @param string $uri - * @param string $urlPrefix - * - * @return bool */ - private function isIoUri($uri, $urlPrefix): bool + private function isIoUri(string $uri, string $urlPrefix): bool { - return strpos(ltrim($uri, '/'), $urlPrefix) === 0; + return str_starts_with(ltrim($uri, '/'), $urlPrefix); } } diff --git a/src/bundle/IO/IbexaIOBundle.php b/src/bundle/IO/IbexaIOBundle.php index 284daff939..b1b8ae4dd7 100644 --- a/src/bundle/IO/IbexaIOBundle.php +++ b/src/bundle/IO/IbexaIOBundle.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO; @@ -32,7 +33,7 @@ public function build(ContainerBuilder $container): void public function getContainerExtension(): ?ExtensionInterface { - if (!isset($this->extension)) { + if (!$this->extension instanceof ExtensionInterface) { $this->extension = new IbexaIOExtension(); $this->extension->addMetadataHandlerFactory('flysystem', new ConfigurationFactory\MetadataHandler\Flysystem()); $this->extension->addMetadataHandlerFactory('legacy_dfs_cluster', new ConfigurationFactory\MetadataHandler\LegacyDFSCluster()); diff --git a/src/bundle/IO/Migration/FileLister/BinaryFileLister.php b/src/bundle/IO/Migration/FileLister/BinaryFileLister.php index c040beef7d..8dae52aa00 100644 --- a/src/bundle/IO/Migration/FileLister/BinaryFileLister.php +++ b/src/bundle/IO/Migration/FileLister/BinaryFileLister.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister; @@ -11,31 +12,27 @@ use Ibexa\Bundle\IO\Migration\FileListerInterface; use Ibexa\Bundle\IO\Migration\MigrationHandler; use Ibexa\Core\IO\Exception\BinaryFileNotFoundException; -use Iterator; use LimitIterator; use Psr\Log\LoggerInterface; class BinaryFileLister extends MigrationHandler implements FileListerInterface { - /** @var \Ibexa\Bundle\IO\Migration\FileLister\FileIteratorInterface */ - private $fileList; + private FileIteratorInterface $fileList; /** @var string Directory where files are stored, within the storage dir. Example: 'original' */ - private $filesDir; + private string $filesDir; /** - * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry $metadataHandlerRegistry - * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry $binarydataHandlerRegistry - * @param \Psr\Log\LoggerInterface|null $logger - * @param \Iterator $fileList + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler> $metadataHandlerRegistry + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler> $binarydataHandlerRegistry * @param string $filesDir Directory where files are stored, within the storage dir. Example: 'original' */ public function __construct( HandlerRegistry $metadataHandlerRegistry, HandlerRegistry $binarydataHandlerRegistry, - LoggerInterface $logger = null, - Iterator $fileList, - $filesDir + FileIteratorInterface $fileList, + string $filesDir, + ?LoggerInterface $logger = null ) { $this->fileList = $fileList; $this->filesDir = $filesDir; @@ -50,10 +47,13 @@ public function countFiles(): int return count($this->fileList); } - public function loadMetadataList($limit = null, $offset = null) + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + */ + public function loadMetadataList(?int $limit = null, ?int $offset = null): array { $metadataList = []; - $fileLimitList = new LimitIterator($this->fileList, $offset, $limit); + $fileLimitList = new LimitIterator($this->fileList, $offset ?? 0, $limit ?? -1); foreach ($fileLimitList as $fileId) { try { diff --git a/src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php b/src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php index b4db64b55f..e8a97ffd15 100644 --- a/src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php +++ b/src/bundle/IO/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister\FileIterator; @@ -17,25 +18,17 @@ */ final class LegacyStorageFileIterator implements FileIteratorInterface { - /** @var mixed Last fetched item. */ - private $item; + private ?string $item; /** @var int Iteration cursor on statement. */ - private $cursor; + private int $cursor; - /** @var \Ibexa\Bundle\IO\Migration\FileLister\FileRowReaderInterface Used to get file rows. */ - private $rowReader; - - /** - * @param \Ibexa\Bundle\IO\Migration\FileLister\FileRowReaderInterface $rowReader - */ - public function __construct(FileRowReaderInterface $rowReader) + public function __construct(private readonly FileRowReaderInterface $rowReader) { - $this->rowReader = $rowReader; } #[\ReturnTypeWillChange] - public function current(): mixed + public function current(): ?string { return $this->item; } @@ -46,7 +39,7 @@ public function next(): void } #[\ReturnTypeWillChange] - public function key(): mixed + public function key(): int { return $this->cursor; } @@ -71,7 +64,7 @@ public function count(): int /** * Fetches the next item from the resultset and moves the cursor forward. */ - private function fetchRow() + private function fetchRow(): void { ++$this->cursor; $fileId = $this->rowReader->getRow(); diff --git a/src/bundle/IO/Migration/FileLister/FileIteratorInterface.php b/src/bundle/IO/Migration/FileLister/FileIteratorInterface.php index 548f9ce550..d38d46f7c8 100644 --- a/src/bundle/IO/Migration/FileLister/FileIteratorInterface.php +++ b/src/bundle/IO/Migration/FileLister/FileIteratorInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister; @@ -12,6 +13,8 @@ /** * Iterates over BinaryFile id entries. + * + * @extends \Iterator */ interface FileIteratorInterface extends Countable, Iterator { diff --git a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageBinaryFileRowReader.php b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageBinaryFileRowReader.php index ebd998022d..c31c449bf5 100644 --- a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageBinaryFileRowReader.php +++ b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageBinaryFileRowReader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister\FileRowReader; @@ -11,8 +12,6 @@ final class LegacyStorageBinaryFileRowReader extends LegacyStorageFileRowReader { /** * Returns the table name to store data in. - * - * @return string */ protected function getStorageTable(): string { diff --git a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php index d71c3504c7..c20bf14d5d 100644 --- a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php +++ b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageFileRowReader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister\FileRowReader; @@ -24,7 +25,7 @@ public function __construct(Connection $connection) $this->result = null; } - final public function init() + final public function init(): void { $selectQuery = $this->connection->createQueryBuilder(); $selectQuery @@ -35,12 +36,13 @@ final public function init() /** * Returns the table name to store data in. - * - * @return string */ - abstract protected function getStorageTable(); + abstract protected function getStorageTable(): string; - final public function getRow() + /** + * @throws \Doctrine\DBAL\Exception + */ + final public function getRow(): ?string { if (null === $this->result) { throw new LogicException('Uninitialized reader. You must call init() before getRow()'); @@ -51,24 +53,20 @@ final public function getRow() return false !== $row ? $this->prependMimeToPath($row['filename'], $row['mime_type']) : null; } - final public function getCount() + final public function getCount(): int { if (null === $this->result) { throw new LogicException('Uninitialized reader. You must call init() before getCount()'); } + /** @var int<0, max> */ return $this->result->rowCount(); } /** * Prepends $path with the first part of the given $mimeType. - * - * @param string $path - * @param string $mimeType - * - * @return string */ - private function prependMimeToPath($path, $mimeType): string + private function prependMimeToPath(string $path, string $mimeType): string { return substr($mimeType, 0, strpos($mimeType, '/')) . '/' . $path; } diff --git a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageMediaFileRowReader.php b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageMediaFileRowReader.php index cf34fc9510..73007d744b 100644 --- a/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageMediaFileRowReader.php +++ b/src/bundle/IO/Migration/FileLister/FileRowReader/LegacyStorageMediaFileRowReader.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister\FileRowReader; @@ -11,8 +12,6 @@ final class LegacyStorageMediaFileRowReader extends LegacyStorageFileRowReader { /** * Returns the table name to store data in. - * - * @return string */ protected function getStorageTable(): string { diff --git a/src/bundle/IO/Migration/FileLister/FileRowReaderInterface.php b/src/bundle/IO/Migration/FileLister/FileRowReaderInterface.php index ecdc468994..28d691aa13 100644 --- a/src/bundle/IO/Migration/FileLister/FileRowReaderInterface.php +++ b/src/bundle/IO/Migration/FileLister/FileRowReaderInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister; @@ -17,19 +18,19 @@ interface FileRowReaderInterface * * Can for instance be used to create and execute a database query. */ - public function init(); + public function init(): void; /** * Returns the next row from the data source. * - * @return mixed|null The row's value, or null if none. + * @return string|null The row's value, or null if none. */ - public function getRow(); + public function getRow(): ?string; /** * Returns the total row count. * - * @return int + * @phpstan-return int<0, max> */ - public function getCount(); + public function getCount(): int; } diff --git a/src/bundle/IO/Migration/FileLister/ImageFileLister.php b/src/bundle/IO/Migration/FileLister/ImageFileLister.php index da3e9c02e8..9ad4521544 100644 --- a/src/bundle/IO/Migration/FileLister/ImageFileLister.php +++ b/src/bundle/IO/Migration/FileLister/ImageFileLister.php @@ -4,50 +4,44 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileLister; +use Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileList; use Ibexa\Bundle\IO\ApiLoader\HandlerRegistry; use Ibexa\Bundle\IO\Migration\FileListerInterface; use Ibexa\Bundle\IO\Migration\MigrationHandler; use Ibexa\Contracts\Core\Variation\VariationPathGenerator; use Ibexa\Core\IO\Exception\BinaryFileNotFoundException; -use Iterator; use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use LimitIterator; use Psr\Log\LoggerInterface; class ImageFileLister extends MigrationHandler implements FileListerInterface { - /** @var \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileList */ - private $imageFileList; + private ImageFileList $imageFileList; - /** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator */ - private $variationPathGenerator; + private VariationPathGenerator $variationPathGenerator; - /** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */ - private $filterConfiguration; + private FilterConfiguration $filterConfiguration; /** @var string Directory where images are stored, within the storage dir. Example: 'images' */ - private $imagesDir; + private string $imagesDir; /** - * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry $metadataHandlerRegistry - * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry $binarydataHandlerRegistry - * @param \Psr\Log\LoggerInterface $logger - * @param \Iterator $imageFileList - * @param \Ibexa\Contracts\Core\Variation\VariationPathGenerator - * @param \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler> $metadataHandlerRegistry + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler> $binarydataHandlerRegistry * @param string $imagesDir Directory where images are stored, within the storage dir. Example: 'images' */ public function __construct( HandlerRegistry $metadataHandlerRegistry, HandlerRegistry $binarydataHandlerRegistry, - LoggerInterface $logger = null, - Iterator $imageFileList, + ImageFileList $imageFileList, VariationPathGenerator $variationPathGenerator, FilterConfiguration $filterConfiguration, - $imagesDir + string $imagesDir, + ?LoggerInterface $logger = null, ) { $this->imageFileList = $imageFileList; $this->variationPathGenerator = $variationPathGenerator; @@ -64,10 +58,10 @@ public function countFiles(): int return count($this->imageFileList); } - public function loadMetadataList($limit = null, $offset = null) + public function loadMetadataList(?int $limit = null, ?int $offset = null): array { $metadataList = []; - $imageLimitList = new LimitIterator($this->imageFileList, $offset, $limit); + $imageLimitList = new LimitIterator($this->imageFileList, $offset ?? 0, $limit ?? -1); $aliasNames = array_keys($this->filterConfiguration->all()); foreach ($imageLimitList as $originalImageId) { diff --git a/src/bundle/IO/Migration/FileListerInterface.php b/src/bundle/IO/Migration/FileListerInterface.php index c6bca6b7a0..1366a715ce 100644 --- a/src/bundle/IO/Migration/FileListerInterface.php +++ b/src/bundle/IO/Migration/FileListerInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration; @@ -14,7 +15,7 @@ interface FileListerInterface extends MigrationHandlerInterface * * @return int|null Number of files, or null if they cannot be counted */ - public function countFiles(); + public function countFiles(): ?int; /** * Loads and returns metadata for files, optionally limited by $limit and $offset. @@ -24,5 +25,5 @@ public function countFiles(); * * @return \Ibexa\Contracts\Core\IO\BinaryFile[] */ - public function loadMetadataList($limit = null, $offset = null); + public function loadMetadataList(?int $limit = null, ?int $offset = null): array; } diff --git a/src/bundle/IO/Migration/FileListerRegistry.php b/src/bundle/IO/Migration/FileListerRegistry.php index 710c33bed0..dec3c3a0ba 100644 --- a/src/bundle/IO/Migration/FileListerRegistry.php +++ b/src/bundle/IO/Migration/FileListerRegistry.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration; @@ -17,16 +18,16 @@ interface FileListerRegistry * * @param string $identifier An identifier string. * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no FileListerInterface exists with this identifier - * * @return \Ibexa\Bundle\IO\Migration\FileListerInterface The FileListerInterface given by the identifier. + * + * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no FileListerInterface exists with this identifier */ - public function getItem($identifier); + public function getItem(string $identifier): FileListerInterface; /** * Returns the identifiers of all registered FileListerInterfaces. * * @return string[] Array of identifier strings. */ - public function getIdentifiers(); + public function getIdentifiers(): array; } diff --git a/src/bundle/IO/Migration/FileListerRegistry/ConfigurableRegistry.php b/src/bundle/IO/Migration/FileListerRegistry/ConfigurableRegistry.php index f1518b998a..2b25068df0 100644 --- a/src/bundle/IO/Migration/FileListerRegistry/ConfigurableRegistry.php +++ b/src/bundle/IO/Migration/FileListerRegistry/ConfigurableRegistry.php @@ -4,9 +4,11 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileListerRegistry; +use Ibexa\Bundle\IO\Migration\FileListerInterface; use Ibexa\Bundle\IO\Migration\FileListerRegistry; use Ibexa\Core\Base\Exceptions\NotFoundException; @@ -15,15 +17,11 @@ */ final class ConfigurableRegistry implements FileListerRegistry { - /** @var \Ibexa\Bundle\IO\Migration\FileListerInterface[] */ - private $registry = []; - /** - * @param \Ibexa\Bundle\IO\Migration\FileListerInterface[] $items Hash of FileListerInterfaces, with identifier string as key. + * @param \Ibexa\Bundle\IO\Migration\FileListerInterface[] $registry Hash of FileListerInterfaces, with identifier string as key. */ - public function __construct(array $items = []) + public function __construct(private readonly array $registry = []) { - $this->registry = $items; } /** @@ -31,11 +29,11 @@ public function __construct(array $items = []) * * @param string $identifier An identifier string. * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no FileListerInterface exists with this identifier - * * @return \Ibexa\Bundle\IO\Migration\FileListerInterface The FileListerInterface given by the identifier. + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If no FileListerInterface exists with this identifier */ - public function getItem($identifier) + public function getItem(string $identifier): FileListerInterface { if (isset($this->registry[$identifier])) { return $this->registry[$identifier]; diff --git a/src/bundle/IO/Migration/FileMigrator/FileMigrator.php b/src/bundle/IO/Migration/FileMigrator/FileMigrator.php index 4440f6cf1d..e7d0c42ddb 100644 --- a/src/bundle/IO/Migration/FileMigrator/FileMigrator.php +++ b/src/bundle/IO/Migration/FileMigrator/FileMigrator.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration\FileMigrator; @@ -43,6 +44,8 @@ private function migrateBinaryFile(BinaryFile $binaryFile): bool $binaryFileCreateStruct = new BinaryFileCreateStruct(); $binaryFileCreateStruct->id = $binaryFile->id; $binaryFileCreateStruct->setInputStream($binaryFileResource); + // determining a mime type is possible only using the metadata handler + $binaryFileCreateStruct->mimeType = $this->fromMetadataHandler->getMimeType($binaryFile->id); try { $this->toBinarydataHandler->create($binaryFileCreateStruct); @@ -70,7 +73,7 @@ private function migrateMetadata(BinaryFile $binaryFile): bool try { $this->toMetadataHandler->create($metadataCreateStruct); } catch (\RuntimeException $e) { - $this->logError("Cannot migrate metadata for: '{$binaryFile->id}'. Error: " . $e->getMessage() . $e->getPrevious()->getMessage()); + $this->logError("Cannot migrate metadata for: '{$binaryFile->id}'. Error: " . $e->getMessage() . $e->getPrevious()?->getMessage()); return false; } diff --git a/src/bundle/IO/Migration/FileMigratorInterface.php b/src/bundle/IO/Migration/FileMigratorInterface.php index 7b0ee46b3b..69652efa0e 100644 --- a/src/bundle/IO/Migration/FileMigratorInterface.php +++ b/src/bundle/IO/Migration/FileMigratorInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration; diff --git a/src/bundle/IO/Migration/MigrationHandler.php b/src/bundle/IO/Migration/MigrationHandler.php index 2a6a0cabd3..b011b62d1f 100644 --- a/src/bundle/IO/Migration/MigrationHandler.php +++ b/src/bundle/IO/Migration/MigrationHandler.php @@ -4,54 +4,50 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration; use Ibexa\Bundle\IO\ApiLoader\HandlerRegistry; +use Ibexa\Core\IO\IOBinarydataHandler; +use Ibexa\Core\IO\IOMetadataHandler; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; /** * The migration handler sets up from/to IO data handlers, and provides logging, for file migrators and listers. */ -abstract class MigrationHandler implements MigrationHandlerInterface +abstract class MigrationHandler implements MigrationHandlerInterface, LoggerAwareInterface { - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry */ - private $metadataHandlerRegistry; + use LoggerAwareTrait; - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry */ - private $binarydataHandlerRegistry; + protected IOMetadataHandler $fromMetadataHandler; - /** @var \Psr\Log\LoggerInterface */ - private $logger; + protected IOBinarydataHandler $fromBinarydataHandler; - /** @var \Ibexa\Core\IO\IOMetadataHandler */ - protected $fromMetadataHandler; + protected IOMetadataHandler $toMetadataHandler; - /** @var \Ibexa\Core\IO\IOBinarydataHandler */ - protected $fromBinarydataHandler; - - /** @var \Ibexa\Core\IO\IOMetadataHandler */ - protected $toMetadataHandler; - - /** @var \Ibexa\Core\IO\IOBinarydataHandler */ - protected $toBinarydataHandler; + protected IOBinarydataHandler $toBinarydataHandler; + /** + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler> $metadataHandlerRegistry + * @param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler> $binarydataHandlerRegistry + */ public function __construct( - HandlerRegistry $metadataHandlerRegistry, - HandlerRegistry $binarydataHandlerRegistry, - LoggerInterface $logger = null + private readonly HandlerRegistry $metadataHandlerRegistry, + private readonly HandlerRegistry $binarydataHandlerRegistry, + ?LoggerInterface $logger = null ) { - $this->metadataHandlerRegistry = $metadataHandlerRegistry; - $this->binarydataHandlerRegistry = $binarydataHandlerRegistry; $this->logger = $logger; } public function setIODataHandlersByIdentifiers( - $fromMetadataHandlerIdentifier, - $fromBinarydataHandlerIdentifier, - $toMetadataHandlerIdentifier, - $toBinarydataHandlerIdentifier - ) { + string $fromMetadataHandlerIdentifier, + string $fromBinarydataHandlerIdentifier, + string $toMetadataHandlerIdentifier, + string $toBinarydataHandlerIdentifier + ): MigrationHandler { $this->fromMetadataHandler = $this->metadataHandlerRegistry->getConfiguredHandler($fromMetadataHandlerIdentifier); $this->fromBinarydataHandler = $this->binarydataHandlerRegistry->getConfiguredHandler($fromBinarydataHandlerIdentifier); $this->toMetadataHandler = $this->metadataHandlerRegistry->getConfiguredHandler($toMetadataHandlerIdentifier); @@ -60,21 +56,21 @@ public function setIODataHandlersByIdentifiers( return $this; } - final protected function logError($message) + final protected function logError(string $message): void { if (isset($this->logger)) { $this->logger->error($message); } } - final protected function logInfo($message) + final protected function logInfo(string $message): void { if (isset($this->logger)) { $this->logger->info($message); } } - final protected function logMissingFile($id) + final protected function logMissingFile(string $id): void { $this->logInfo("File with id $id not found"); } diff --git a/src/bundle/IO/Migration/MigrationHandlerInterface.php b/src/bundle/IO/Migration/MigrationHandlerInterface.php index bee26d49d8..3d32c33597 100644 --- a/src/bundle/IO/Migration/MigrationHandlerInterface.php +++ b/src/bundle/IO/Migration/MigrationHandlerInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\IO\Migration; @@ -11,19 +12,11 @@ interface MigrationHandlerInterface { /** * Set the from/to handlers based on identifiers. - * Returns the MigrationHandler. - * - * @param string $fromMetadataHandlerIdentifier - * @param string $fromBinarydataHandlerIdentifier - * @param string $toMetadataHandlerIdentifier - * @param string $toBinarydataHandlerIdentifier - * - * @return MigrationHandlerInterface */ public function setIODataHandlersByIdentifiers( - $fromMetadataHandlerIdentifier, - $fromBinarydataHandlerIdentifier, - $toMetadataHandlerIdentifier, - $toBinarydataHandlerIdentifier - ); + string $fromMetadataHandlerIdentifier, + string $fromBinarydataHandlerIdentifier, + string $toMetadataHandlerIdentifier, + string $toBinarydataHandlerIdentifier + ): MigrationHandler; } diff --git a/src/bundle/IO/Resources/config/io.yml b/src/bundle/IO/Resources/config/io.yml index cd694a0b2a..27afe35de9 100644 --- a/src/bundle/IO/Resources/config/io.yml +++ b/src/bundle/IO/Resources/config/io.yml @@ -1,13 +1,11 @@ services: Ibexa\Bundle\IO\Command\MigrateFilesCommand: - class: Ibexa\Bundle\IO\Command\MigrateFilesCommand + autoconfigure: true arguments: - - '%ibexa.io.metadata_handlers%' - - '%ibexa.io.binarydata_handlers%' - - '@Ibexa\Bundle\IO\Migration\FileListerRegistry\ConfigurableRegistry' - - '@Ibexa\Bundle\IO\Migration\FileMigrator\FileMigrator' - tags: - - { name: console.command } + $configuredMetadataHandlers: '%ibexa.io.metadata_handlers%' + $configuredBinarydataHandlers: '%ibexa.io.binarydata_handlers%' + $fileListerRegistry: '@Ibexa\Bundle\IO\Migration\FileListerRegistry\ConfigurableRegistry' + $fileMigrator: '@Ibexa\Bundle\IO\Migration\FileMigrator\FileMigrator' Ibexa\Bundle\IO\Migration\FileListerRegistry\ConfigurableRegistry: class: Ibexa\Bundle\IO\Migration\FileListerRegistry\ConfigurableRegistry @@ -15,16 +13,16 @@ services: Ibexa\Bundle\IO\Migration\MigrationHandler: class: Ibexa\Bundle\IO\Migration\MigrationHandler arguments: - - '@ibexa.core.io.metadata_handler.registry' - - '@ibexa.core.io.binarydata_handler.registry' - - "@logger" + $metadataHandlerRegistry: '@ibexa.core.io.metadata_handler.registry' + $binarydataHandlerRegistry: '@ibexa.core.io.binarydata_handler.registry' + $logger: '@?logger' ibexa.core.io.migration.file_lister.binary_file_lister: class: Ibexa\Bundle\IO\Migration\FileLister\BinaryFileLister parent: Ibexa\Bundle\IO\Migration\MigrationHandler arguments: - - '@ibexa.core.io.migration.file_lister.file_iterator.binary_file_iterator' - - "%ibexa.site_access.config.default.binary_dir%" + $fileList: '@ibexa.core.io.migration.file_lister.file_iterator.binary_file_iterator' + $filesDir: '%ibexa.site_access.config.default.binary_dir%' tags: - { name: "ibexa.io.migration.file_lister", identifier: "binary_file" } lazy: true @@ -33,20 +31,19 @@ services: class: Ibexa\Bundle\IO\Migration\FileLister\BinaryFileLister parent: Ibexa\Bundle\IO\Migration\MigrationHandler arguments: - - '@ibexa.core.io.migration.file_lister.file_iterator.media_file_iterator' - - "%ibexa.site_access.config.default.binary_dir%" + $fileList: '@ibexa.core.io.migration.file_lister.file_iterator.media_file_iterator' + $filesDir: '%ibexa.site_access.config.default.binary_dir%' tags: - { name: "ibexa.io.migration.file_lister", identifier: "media_file" } lazy: true Ibexa\Bundle\IO\Migration\FileLister\ImageFileLister: - class: Ibexa\Bundle\IO\Migration\FileLister\ImageFileLister parent: Ibexa\Bundle\IO\Migration\MigrationHandler arguments: - - '@Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList' - - '@ibexa.image_alias.variation_path_generator' - - "@liip_imagine.filter.configuration" - - "%ibexa.site_access.config.default.image.published_images_dir%" + $imageFileList: '@Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList' + $variationPathGenerator: '@ibexa.image_alias.variation_path_generator' + $filterConfiguration: "@liip_imagine.filter.configuration" + $imagesDir: '%ibexa.site_access.config.default.image.published_images_dir%' tags: - { name: "ibexa.io.migration.file_lister", identifier: "image_file" } lazy: true diff --git a/src/contracts/FieldType/FieldType.php b/src/contracts/FieldType/FieldType.php index 3b65d8502e..20ece06a58 100644 --- a/src/contracts/FieldType/FieldType.php +++ b/src/contracts/FieldType/FieldType.php @@ -4,10 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\FieldType; use Ibexa\Contracts\Core\Persistence\Content\FieldValue; +use Ibexa\Contracts\Core\Repository\Values\Content\RelationType; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; /** @@ -37,105 +39,86 @@ abstract class FieldType * to prefix the field-type identifier by a unique string that identifies * the implementer. A good identifier could for example take your companies main * domain name as a prefix in reverse order. - * - * @return string */ - abstract public function getFieldTypeIdentifier(); + abstract public function getFieldTypeIdentifier(): string; /** - * Returns a human readable string representation from a given value. + * Returns a human-readable string representation from a given value. * - * It will be used to generate content name and url alias if current field + * It will be used to generate content name and url alias if the current field * is designated to be used in the content name/urlAlias pattern. * * The used $value can be assumed to be already accepted by {@see FieldType::acceptValue()}. - * - * @param \Ibexa\Contracts\Core\FieldType\Value $value - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition - * @param string $languageCode - * - * @return string */ abstract public function getName(Value $value, FieldDefinition $fieldDefinition, string $languageCode): string; /** * Returns a schema for the settings expected by the FieldType. * - * Returns an arbitrary value, representing a schema for the settings of + * Returns an arbitrary hash map, representing a schema for the settings of * the FieldType. * - * Explanation: There are no possible generic schemas for defining settings - * input, which is why no schema for the return value of this method is - * defined. It is up to the implementer to define and document a schema for - * the return value and document it. In addition, it is necessary that all - * consumers of this interface (e.g. Public API, REST API, GUIs, ...) - * provide plugin mechanisms to hook adapters for the specific FieldType + * It is up to the implementer to define and document an array shape of a schema hash map for + * the return value. In addition, it is necessary that all consumers of this interface + * (e.g., Public API, REST API, GUIs, ...) provide plugin mechanisms to hook adapters for the specific FieldType * into. These adapters then need to be either shipped with the FieldType * or need to be implemented by a third party. If there is no adapter * available for a specific FieldType, it will not be usable with the * consumer. * - * @return mixed + * @return array */ - abstract public function getSettingsSchema(); + abstract public function getSettingsSchema(): array; /** * Returns a schema for the validator configuration expected by the FieldType. * - * Returns an arbitrary value, representing a schema for the validator - * configuration of the FieldType. + * Schema has to be a hash map (an `array`), which contains + * rudimentary settings structures, like e.g., for the "ibexa_string" FieldType: * - * Explanation: There are no possible generic schemas for defining settings - * input, which is why no schema for the return value of this method is - * defined. It is up to the implementer to define and document a schema for - * the return value and document it. In addition, it is necessary that all - * consumers of this interface (e.g. Public API, REST API, GUIs, ...) - * provide plugin mechanisms to hook adapters for the specific FieldType + * ``` + * [ + * 'stringLength' => [ + * 'minStringLength' => [ + * 'type' => 'int', + * 'default' => 0, + * ], + * 'maxStringLength' => [ + * 'type' => 'int' + * 'default' => null, + * ], + * ], + * ]; + * ``` + * + * It is up to the implementer to define and document an array shape of a schema for + * the return value. In addition, it is necessary that all consumers of this interface + * (e.g., Public API, REST API, GUIs, ...) provide plugin mechanisms to hook adapters for the specific FieldType * into. These adapters then need to be either shipped with the FieldType * or need to be implemented by a third party. If there is no adapter * available for a specific FieldType, it will not be usable with the * consumer. * - * Best practice: - * - * It is considered best practice to return a hash map, which contains - * rudimentary settings structures, like e.g. for the "ibexa_string" FieldType - * - * ``` - * [ - * 'stringLength' => [ - * 'minStringLength' => [ - * 'type' => 'int', - * 'default' => 0, - * ], - * 'maxStringLength' => [ - * 'type' => 'int' - * 'default' => null, - * ], - * ], - * ]; - * ``` - * - * @return mixed + * @return array */ - abstract public function getValidatorConfigurationSchema(); + abstract public function getValidatorConfigurationSchema(): array; /** * Validates a field based on the validator configuration in the field definition. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field * @param \Ibexa\Contracts\Core\FieldType\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - abstract public function validate(FieldDefinition $fieldDef, Value $value); + abstract public function validate(FieldDefinition $fieldDef, Value $value): array; /** * Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. * - * This methods determines if the given $validatorConfiguration is + * This method determines if the given $validatorConfiguration is * structurally correct and complies to the validator configuration schema * returned by {@see FieldType::getValidatorConfigurationSchema()}. * @@ -143,70 +126,60 @@ abstract public function validate(FieldDefinition $fieldDef, Value $value); * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - abstract public function validateValidatorConfiguration($validatorConfiguration); + abstract public function validateValidatorConfiguration(mixed $validatorConfiguration): array; /** * Applies the default values to the given $validatorConfiguration of a FieldDefinitionCreateStruct. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param mixed $validatorConfiguration */ - abstract public function applyDefaultValidatorConfiguration(&$validatorConfiguration); + abstract public function applyDefaultValidatorConfiguration(mixed &$validatorConfiguration): void; /** * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. * - * This methods determines if the given $fieldSettings are structurally + * This method determines if the given $fieldSettings are structurally * correct and comply to the settings schema returned by {@see FieldType::getSettingsSchema()}. * - * @param mixed $fieldSettings + * @param array $fieldSettings * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - abstract public function validateFieldSettings($fieldSettings); + abstract public function validateFieldSettings(array $fieldSettings): array; /** * Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @param array $fieldSettings * - * @param mixed $fieldSettings + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - abstract public function applyDefaultSettings(&$fieldSettings); + abstract public function applyDefaultSettings(array &$fieldSettings): void; /** * Indicates if the field type supports indexing and sort keys for searching. - * - * @return bool */ - abstract public function isSearchable(); + abstract public function isSearchable(): bool; /** * Indicates if the field definition of this type can appear only once in the same ContentType. - * - * @return bool */ - abstract public function isSingular(); + abstract public function isSingular(): bool; /** * Indicates if the field definition of this type can be added to a ContentType with Content instances. - * - * @return bool */ - abstract public function onlyEmptyInstance(); + abstract public function onlyEmptyInstance(): bool; /** * Returns the empty value for this field type. * - * This value will be used, if no value was provided for a field of this + * This value will be used if no value was provided for a field of this * type and no default value was specified in the field definition. It is * also used to determine that a user intentionally (or unintentionally) did not * set a non-empty value. - * - * @return \Ibexa\Contracts\Core\FieldType\Value */ - abstract public function getEmptyValue(); + abstract public function getEmptyValue(): Value; /** * Returns if the given $value is considered empty by the field type. @@ -214,17 +187,13 @@ abstract public function getEmptyValue(); * Usually, only the value returned by {@see FieldType::getEmptyValue()} is * considered empty. The given $value can be safely assumed to have already * been processed by {@see FieldType::acceptValue()}. - * - * @param \Ibexa\Contracts\Core\FieldType\Value $value - * - * @return bool */ - abstract public function isEmptyValue(Value $value); + abstract public function isEmptyValue(Value $value): bool; /** * Potentially builds and checks the type and structure of the $inputValue. * - * This method first inspects $inputValue and convert it into a dedicated + * This method first inspects $inputValue and converts it into a dedicated * value object. * * After that, the value is checked for structural validity. @@ -233,55 +202,43 @@ abstract public function isEmptyValue(Value $value); * format. * * Note that this method must also cope with the empty value for the field - * type as e.g. returned by {@see FieldType::getEmptyValue()}. + * type as e.g., returned by {@see FieldType::getEmptyValue()}. + * + * @return \Ibexa\Contracts\Core\FieldType\Value The potentially converted and structurally plausible value. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if the parameter is not of the supported value sub type * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if the value does not match the expected structure - * - * @param mixed $inputValue - * - * @return \Ibexa\Contracts\Core\FieldType\Value The potentially converted and structurally plausible value. */ - abstract public function acceptValue($inputValue); + abstract public function acceptValue(mixed $inputValue): Value; /** - * Converts an $hash to the Value defined by the field type. + * Converts a $hash to the Value defined by the field type. * * This is the reverse operation to {@see FieldType::toHash()}. At least the hash * format generated by {@see FieldType::toHash()} must be converted in reverse. * Additional formats might be supported in the rare case that this is * necessary. See the class description for more details on a hash format. - * - * @param mixed $hash - * - * @return \Ibexa\Contracts\Core\FieldType\Value */ - abstract public function fromHash($hash); + abstract public function fromHash(mixed $hash): Value; /** * Converts the given $value into a plain hash format. * * Converts the given $value into a plain hash format, which can be used to - * transfer the value through plain text formats, e.g. XML, which do not + * transfer the value through plain text formats, e.g., XML, which do not * support complex structures like objects. See the class level doc block * for additional information. See the class description for more details on a hash format. - * - * @param \Ibexa\Contracts\Core\FieldType\Value $value - * - * @return mixed */ - abstract public function toHash(Value $value); + abstract public function toHash(Value $value): mixed; /** * Converts the given $fieldSettings to a simple hash format. * * See the class description for more details on a hash format. * - * @param mixed $fieldSettings - * - * @return array|scalar|null + * @return array|scalar|null */ - abstract public function fieldSettingsToHash($fieldSettings); + abstract public function fieldSettingsToHash(mixed $fieldSettings): mixed; /** * Converts the given $fieldSettingsHash to field settings of the type. @@ -289,22 +246,20 @@ abstract public function fieldSettingsToHash($fieldSettings); * This is the reverse operation of {@see FieldType::fieldSettingsToHash()}. * See the class description for more details on a hash format. * - * @param array|scalar|null $fieldSettingsHash + * @param array|scalar|null $fieldSettingsHash * * @return mixed */ - abstract public function fieldSettingsFromHash($fieldSettingsHash); + abstract public function fieldSettingsFromHash(mixed $fieldSettingsHash): mixed; /** * Converts the given $validatorConfiguration to a simple hash format. * * See the class description for more details on a hash format. * - * @param mixed $validatorConfiguration - * - * @return array|scalar|null + * @return array|scalar|null */ - abstract public function validatorConfigurationToHash($validatorConfiguration); + abstract public function validatorConfigurationToHash(mixed $validatorConfiguration): mixed; /** * Converts the given $validatorConfigurationHash to a validator @@ -312,16 +267,14 @@ abstract public function validatorConfigurationToHash($validatorConfiguration); * * See the class description for more details on a hash format. * - * @param array|scalar|null $validatorConfigurationHash - * - * @return mixed + * @param array|scalar|null $validatorConfigurationHash */ - abstract public function validatorConfigurationFromHash($validatorConfigurationHash); + abstract public function validatorConfigurationFromHash(mixed $validatorConfigurationHash): mixed; /** * Converts a $value to a persistence value. * - * In this method the field type puts the data which is stored in the field of content in the repository + * In this method, the field type puts the data which is stored in the field of content in the repository * into the property FieldValue::data. The format of $data is a primitive, an array (map) or an object, which * is then canonically converted to e.g. json/xml structures by future storage engines without * further conversions. For mapping the $data to the legacy database an appropriate Converter @@ -340,43 +293,33 @@ abstract public function validatorConfigurationFromHash($validatorConfigurationH * * @return \Ibexa\Contracts\Core\Persistence\Content\FieldValue the value processed by the storage engine */ - abstract public function toPersistenceValue(Value $value); + abstract public function toPersistenceValue(Value $value): FieldValue; /** * Converts a persistence $value to a Value. * * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Contracts\Core\FieldType\Value */ - abstract public function fromPersistenceValue(FieldValue $fieldValue); + abstract public function fromPersistenceValue(FieldValue $fieldValue): Value; /** - * Returns relation data extracted from value. + * Returns relation data extracted from the given Value. * - * Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, + * Not intended for {@see \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON} type relations, * there is an API for handling those. * - * @param \Ibexa\Contracts\Core\FieldType\Value $value - * - * @return array Hash with relation type as key and array of destination content IDs as value. + * @return array<\Ibexa\Contracts\Core\Repository\Values\Content\RelationType, int[]> Hash with a relation type as key and an array of destination content IDs as value. * * Example: * ``` * [ - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => [ - * 'contentIds' => [12, 13, 14], - * 'locationIds' => [24] - * ], - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => [ - * 'contentIds" => [12], - * 'locationIds' => [24, 45] - * ], - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => [12] + * RelationType::LINK->value => [12, 13, 14], + * RelationType::EMBED->value => [12], + * RelationType::FIELD->value => [12] * ] * ``` + * + * @see \Ibexa\Contracts\Core\Repository\Values\Content\RelationType */ - abstract public function getRelations(Value $value); + abstract public function getRelations(Value $value): array; } diff --git a/src/contracts/FieldType/Generic/Type.php b/src/contracts/FieldType/Generic/Type.php index 0af7c518e5..831d9613de 100644 --- a/src/contracts/FieldType/Generic/Type.php +++ b/src/contracts/FieldType/Generic/Type.php @@ -17,17 +17,17 @@ use Ibexa\Contracts\Core\FieldType\ValueSerializerInterface; use Ibexa\Contracts\Core\Persistence\Content\FieldValue as PersistenceValue; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Value as AbstractFieldTypeValue; +use LogicException; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; abstract class Type extends FieldType { - /** @var \Ibexa\Contracts\Core\FieldType\ValueSerializerInterface */ - protected $serializer; + protected ValueSerializerInterface $serializer; - /** @var \Symfony\Component\Validator\Validator\ValidatorInterface */ - protected $validator; + protected ValidatorInterface $validator; public function __construct(ValueSerializerInterface $serializer, ValidatorInterface $validator) { @@ -47,7 +47,7 @@ public function getEmptyValue(): Value return new $class(); } - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if ($hash) { return $this->serializer->denormalize($hash, $this->getValueClass()); @@ -56,6 +56,9 @@ public function fromHash($hash): Value return $this->getEmptyValue(); } + /** + * @return array|null + */ public function toHash(Value $value): ?array { if ($this->isEmptyValue($value)) { @@ -114,7 +117,7 @@ public function validate(FieldDefinition $fieldDefinition, Value $value): array ); } - public function validateValidatorConfiguration($validatorConfiguration): array + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -128,7 +131,7 @@ public function validateValidatorConfiguration($validatorConfiguration): array return $validationErrors; } - public function applyDefaultValidatorConfiguration(&$validatorConfiguration): void + public function applyDefaultValidatorConfiguration(mixed &$validatorConfiguration): void { if ($validatorConfiguration !== null && !is_array($validatorConfiguration)) { throw new InvalidArgumentType('$validatorConfiguration', 'array|null', $validatorConfiguration); @@ -149,9 +152,9 @@ public function applyDefaultValidatorConfiguration(&$validatorConfiguration): vo } } - public function validateFieldSettings($fieldSettings): array + public function validateFieldSettings(array $fieldSettings): array { - if (empty($this->getSettingsSchema()) && !empty($fieldSettings)) { + if (!empty($fieldSettings) && empty($this->getSettingsSchema())) { return [ new NonConfigurableValidationError($this->getFieldTypeIdentifier(), 'fieldType'), ]; @@ -166,15 +169,11 @@ public function validateFieldSettings($fieldSettings): array ); } - public function applyDefaultSettings(&$fieldSettings): void + public function applyDefaultSettings(array &$fieldSettings): void { - if ($fieldSettings !== null && !is_array($fieldSettings)) { - throw new InvalidArgumentType('$fieldSettings', 'array|null', $fieldSettings); - } - foreach ($this->getSettingsSchema() as $settingName => $settingConfiguration) { // Checking that a default entry exists in the settingsSchema but that no value has been provided - if (!array_key_exists($settingName, (array)$fieldSettings) && array_key_exists('default', $settingConfiguration)) { + if (!array_key_exists($settingName, $fieldSettings) && array_key_exists('default', $settingConfiguration)) { $fieldSettings[$settingName] = $settingConfiguration['default']; } } @@ -212,7 +211,7 @@ public function toPersistenceValue(Value $value): PersistenceValue ); } - public function fromPersistenceValue(PersistenceValue $fieldValue) + public function fromPersistenceValue(PersistenceValue $fieldValue): Value { return $this->fromHash($fieldValue->data); } @@ -237,7 +236,7 @@ public function isEmptyValue(Value $value): bool return $value == $this->getEmptyValue(); } - final public function acceptValue($inputValue): Value + final public function acceptValue(mixed $inputValue): Value { if ($inputValue === null) { return $this->getEmptyValue(); @@ -294,11 +293,23 @@ protected function createValueFromInput($inputValue) /** * Returns FQN of class representing Field Type Value. * - * @return string + * @return class-string<\Ibexa\Contracts\Core\FieldType\Value> */ protected function getValueClass(): string { - return substr_replace(static::class, 'Value', strrpos(static::class, '\\') + 1); + $valueClass = substr_replace(static::class, 'Value', strrpos(static::class, '\\') + 1); + if (!is_a($valueClass, Value::class, true)) { + throw new LogicException( + sprintf( + '%s is not a valid field type value class. Make sure it either implements %s or extends %s', + $valueClass, + Value::class, + AbstractFieldTypeValue::class + ) + ); + } + + return $valueClass; } /** @@ -306,7 +317,7 @@ protected function getValueClass(): string * * This is an operation method for {@see Type::acceptValue()}. * - * Default implementation expects the value class to reside in the same namespace as its + * The Default implementation expects the value class to reside in the same namespace as its * FieldType class and is named "Value". * * Example implementation: @@ -324,7 +335,7 @@ protected function getValueClass(): string * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If the parameter is not an instance of the supported value subtype. */ - protected function checkValueType($value): void + protected function checkValueType(mixed $value): void { $valueClass = $this->getValueClass(); if (!$value instanceof $valueClass) { @@ -332,22 +343,22 @@ protected function checkValueType($value): void } } - public function fieldSettingsToHash($fieldSettings) + public function fieldSettingsToHash(mixed $fieldSettings): mixed { return $fieldSettings; } - public function fieldSettingsFromHash($fieldSettingsHash) + public function fieldSettingsFromHash(mixed $fieldSettingsHash): mixed { return $fieldSettingsHash; } - public function validatorConfigurationToHash($validatorConfiguration) + public function validatorConfigurationToHash(mixed $validatorConfiguration): mixed { return $validatorConfiguration; } - public function validatorConfigurationFromHash($validatorConfiguration) + public function validatorConfigurationFromHash(mixed $validatorConfiguration): mixed { return $validatorConfiguration; } diff --git a/src/contracts/FieldType/Value.php b/src/contracts/FieldType/Value.php index 6b5a2d4517..2e24ddfe83 100644 --- a/src/contracts/FieldType/Value.php +++ b/src/contracts/FieldType/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\FieldType; @@ -14,8 +15,6 @@ interface Value { /** * Returns a string representation of the field value. - * - * @return string */ - public function __toString(); + public function __toString(): string; } diff --git a/src/contracts/IO/BinaryFile.php b/src/contracts/IO/BinaryFile.php index ef78cb68b9..712fdca3d9 100644 --- a/src/contracts/IO/BinaryFile.php +++ b/src/contracts/IO/BinaryFile.php @@ -4,9 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\IO; +use DateTimeInterface; + /** * This class provides abstract access to binary files. * @@ -15,32 +18,27 @@ class BinaryFile { /** - * Unique persistence layer identifier for this file + * Unique persistence layer identifier for this file. + * * Ex: images/media/images/ibexa-logo/209-1-eng-GB/Ibexa-Logo.gif, * or original/application/2b042138835bb5f48beb9c9df6e86de4.pdf. - * - * @var string */ - public $id; + public string $id; /** * File size, in bytes. * * @var int */ - public $size; + public int $size; /** * File modification time. - * - * @var \DateTime */ - public $mtime; + public DateTimeInterface $mtime; /** * HTTP URI to the binary file. - * - * @var string */ - public $uri; + public string $uri; } diff --git a/src/contracts/IO/BinaryFileCreateStruct.php b/src/contracts/IO/BinaryFileCreateStruct.php index 01621157a1..3d3ed9616d 100644 --- a/src/contracts/IO/BinaryFileCreateStruct.php +++ b/src/contracts/IO/BinaryFileCreateStruct.php @@ -4,9 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\IO; +use DateTimeInterface; + /** * Create struct for BinaryFile objects. */ @@ -14,45 +17,39 @@ class BinaryFileCreateStruct { /** * File size, in bytes. - * - * @var int */ - public $size; + public int $size; /** * File modification time. - * - * @var \DateTime */ - public $mtime; + public DateTimeInterface $mtime; /** - * The file's mime type + * The file's mime type. + * * If not provided, will be auto-detected by the IOService * Example: text/xml. - * - * @var string */ - public $mimeType; + public string $mimeType; /** - * Unique identifier for this file + * Unique identifier for this file. + * * Ex: images/media/images/ibexa-logo/209-1-eng-GB/Ibexa-Logo.gif, * or original/application/2b042138835bb5f48beb9c9df6e86de4.pdf. - * - * @var mixed */ - public $id; + public string $id; /** @var resource */ - private $inputStream; + private mixed $inputStream; /** * Returns the file's input resource. * * @return resource */ - public function getInputStream() + public function getInputStream(): mixed { return $this->inputStream; } @@ -62,7 +59,7 @@ public function getInputStream() * * @param resource $inputStream */ - public function setInputStream($inputStream) + public function setInputStream(mixed $inputStream): void { $this->inputStream = $inputStream; } diff --git a/src/contracts/IO/MimeTypeDetector.php b/src/contracts/IO/MimeTypeDetector.php index 7f8885c834..de40d65769 100644 --- a/src/contracts/IO/MimeTypeDetector.php +++ b/src/contracts/IO/MimeTypeDetector.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\IO; @@ -12,18 +13,14 @@ interface MimeTypeDetector /** * Returns the MIME type of the file identified by $path. * - * @param string $path - * - * @return string + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function getFromPath($path); + public function getFromPath(string $path): string; /** * Returns the MIME type of the data in $buffer. * - * @param string $buffer - * - * @return string + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function getFromBuffer($buffer); + public function getFromBuffer(string $buffer): string; } diff --git a/src/contracts/Persistence/Content/FieldValue.php b/src/contracts/Persistence/Content/FieldValue.php index 2c47ad973d..d484f7ec67 100644 --- a/src/contracts/Persistence/Content/FieldValue.php +++ b/src/contracts/Persistence/Content/FieldValue.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Contracts\Core\Persistence\Content; @@ -16,12 +17,14 @@ class FieldValue extends ValueObject * * Either a scalar (primitive), null or an array (map) of scalar values. * - * Note: For the legacy storage engine we will need adaptors to map them to + * Note: For the legacy storage engine, we will need adaptors to map them to * the existing database fields, like data_int, data_float, data_text. * - * @var int|float|bool|string|array|null + * @var int|float|bool|string|array|null + * + * @phpstan-var scalar|array|null */ - public $data; + public mixed $data; /** * Mixed external field data. @@ -35,15 +38,17 @@ class FieldValue extends ValueObject * * @var mixed */ - public $externalData; + public mixed $externalData; /** * A value which can be used for sorting. * - * Note: For the "old" storage engine we will need adaptors to map them to + * Note: For the "old" storage engine, we will need adaptors to map them to * the existing database fields, like sort_key_int, sort_key_string * * @var int|float|bool|string|null + * + * @phpstan-var scalar|null */ - public $sortKey; + public mixed $sortKey; } diff --git a/src/contracts/Repository/FieldType.php b/src/contracts/Repository/FieldType.php index cc2468c387..db4722d4c6 100644 --- a/src/contracts/Repository/FieldType.php +++ b/src/contracts/Repository/FieldType.php @@ -26,30 +26,16 @@ interface FieldType public function getFieldTypeIdentifier(): string; /** - * Returns a human readable string representation from the given $value. + * Returns a human-readable string representation from the given $value. */ public function getName(Value $value, FieldDefinition $fieldDefinition, string $languageCode): string; /** - * Returns a schema for the settings expected by the FieldType. + * @see \Ibexa\Contracts\Core\FieldType\FieldType::getSettingsSchema * - * Returns an arbitrary value, representing a schema for the settings of - * the FieldType. - * - * Explanation: There are no possible generic schemas for defining settings - * input, which is why no schema for the return value of this method is - * defined. It is up to the implementer to define and document a schema for - * the return value and document it. In addition, it is necessary that all - * consumers of this interface (e.g. Public API, REST API, GUIs, ...) - * provide plugin mechanisms to hook adapters for the specific FieldType - * into. These adapters then need to be either shipped with the FieldType - * or need to be implemented by a third party. If there is no adapter - * available for a specific FieldType, it will not be usable with the - * consumer. - * - * @return mixed + * @return array */ - public function getSettingsSchema(); + public function getSettingsSchema(): array; /** * Returns a schema for the validator configuration expected by the FieldType. diff --git a/src/contracts/Variation/VariationHandler.php b/src/contracts/Variation/VariationHandler.php index e60273cb39..156f241b52 100644 --- a/src/contracts/Variation/VariationHandler.php +++ b/src/contracts/Variation/VariationHandler.php @@ -25,6 +25,10 @@ interface VariationHandler * Variations might be applicable for images (aliases), documents... * * @param array $parameters Hash of arbitrary parameters useful to generate the variation + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ public function getVariation( Field $field, diff --git a/src/lib/Base/Exceptions/NotFoundException.php b/src/lib/Base/Exceptions/NotFoundException.php index f9a7437e4c..d9643902b3 100644 --- a/src/lib/Base/Exceptions/NotFoundException.php +++ b/src/lib/Base/Exceptions/NotFoundException.php @@ -8,10 +8,10 @@ namespace Ibexa\Core\Base\Exceptions; -use Exception; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException as APINotFoundException; use Ibexa\Core\Base\Translatable; use Ibexa\Core\Base\TranslatableBase; +use Throwable; /** * Not Found Exception implementation. @@ -28,7 +28,7 @@ class NotFoundException extends APINotFoundException implements Httpable, Transl /** * Generates: Could not find '{$what}' with identifier '{$identifier}'. */ - public function __construct(string $what, mixed $identifier, ?Exception $previous = null) + public function __construct(string $what, mixed $identifier, ?Throwable $previous = null) { $identifierStr = is_string($identifier) ? $identifier : var_export($identifier, true); $this->setMessageTemplate("Could not find '%what%' with identifier '%identifier%'"); diff --git a/src/lib/FieldType/Author/AuthorCollection.php b/src/lib/FieldType/Author/AuthorCollection.php index 2d1081ccbf..6bfea87c87 100644 --- a/src/lib/FieldType/Author/AuthorCollection.php +++ b/src/lib/FieldType/Author/AuthorCollection.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Author; diff --git a/src/lib/FieldType/Author/Type.php b/src/lib/FieldType/Author/Type.php index 46545a73ef..bda6da9700 100644 --- a/src/lib/FieldType/Author/Type.php +++ b/src/lib/FieldType/Author/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Author; @@ -38,7 +39,7 @@ class Type extends FieldType implements TranslationContainerInterface */ public const DEFAULT_CURRENT_USER = 1; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'defaultAuthor' => [ 'type' => 'choice', 'default' => self::DEFAULT_VALUE_EMPTY, @@ -60,13 +61,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $value->authors[0]->name ?? ''; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Author\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -105,10 +100,7 @@ protected function checkValueStructure(BaseValue $value) } } - /** - * {@inheritdoc} - */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): string|false { if (empty($value->authors)) { return false; @@ -125,13 +117,9 @@ protected function getSortInfo(BaseValue $value) } /** - * Converts a $hash to the Value defined by the field type. - * * @phpstan-param TAuthorHash $hash - * - * @return \Ibexa\Core\FieldType\Author\Value $value */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value( array_map( @@ -144,8 +132,6 @@ static function ($author) { } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Author\Value $value * * @phpstan-return TAuthorHash @@ -160,24 +146,12 @@ static function ($author) { ); } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param array $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -188,13 +162,11 @@ public function validateFieldSettings($fieldSettings) $validationErrors[] = $settingNameError; } - switch ($name) { - case 'defaultAuthor': - $settingValueError = $this->validateDefaultAuthorSetting($name, $value); - if ($settingValueError instanceof ValidationError) { - $validationErrors[] = $settingValueError; - } - break; + if ($name === 'defaultAuthor') { + $settingValueError = $this->validateDefaultAuthorSetting($name, $value); + if ($settingValueError instanceof ValidationError) { + $validationErrors[] = $settingValueError; + } } } diff --git a/src/lib/FieldType/Author/Value.php b/src/lib/FieldType/Author/Value.php index bac3dfa70b..c262f55659 100644 --- a/src/lib/FieldType/Author/Value.php +++ b/src/lib/FieldType/Author/Value.php @@ -4,22 +4,21 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Author; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Author field type. + * Value for the Author field type. */ class Value extends BaseValue { /** * List of authors. - * - * @var \Ibexa\Core\FieldType\Author\AuthorCollection */ - public $authors; + public readonly AuthorCollection $authors; /** * Construct a new Value object and initialize with $authors. @@ -29,20 +28,19 @@ class Value extends BaseValue public function __construct(array $authors = []) { $this->authors = new AuthorCollection($authors); + + parent::__construct(); } - public function __toString() + public function __toString(): string { - if (empty($this->authors)) { + if ($this->authors->count() <= 0) { return ''; } $authorNames = []; - - if ($this->authors instanceof AuthorCollection) { - foreach ($this->authors as $author) { - $authorNames[] = $author->name; - } + foreach ($this->authors as $author) { + $authorNames[] = $author->name; } return implode(', ', $authorNames); diff --git a/src/lib/FieldType/BaseNumericType.php b/src/lib/FieldType/BaseNumericType.php index aae72e23ea..c0a72b334f 100644 --- a/src/lib/FieldType/BaseNumericType.php +++ b/src/lib/FieldType/BaseNumericType.php @@ -26,11 +26,11 @@ public function getValidator(string $validatorIdentifier): ?Validator /** * Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. * - * @param array $validatorConfiguration + * @param mixed $validatorConfiguration * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration): array + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; $validatorValidationErrors = []; diff --git a/src/lib/FieldType/BaseTextType.php b/src/lib/FieldType/BaseTextType.php index 3e28d47f99..79eb933f7a 100644 --- a/src/lib/FieldType/BaseTextType.php +++ b/src/lib/FieldType/BaseTextType.php @@ -41,7 +41,7 @@ public function getName( */ public function isEmptyValue(FieldTypeValueInterface $value): bool { - return $value->text === null || trim($value->text) === ''; + return trim($value->text) === ''; } /** diff --git a/src/lib/FieldType/BinaryBase/Type.php b/src/lib/FieldType/BinaryBase/Type.php index e8316937d1..fd503aa1d3 100644 --- a/src/lib/FieldType/BinaryBase/Type.php +++ b/src/lib/FieldType/BinaryBase/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\BinaryBase; @@ -22,7 +23,7 @@ */ abstract class Type extends FieldType { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'FileSizeValidator' => [ 'maxFileSize' => [ 'type' => 'int', @@ -169,24 +170,13 @@ protected function completeValue(BaseValue $value) /** * BinaryBase does not support sorting, yet. - * - * @param \Ibexa\Core\FieldType\BinaryBase\Value $value - * - * @return mixed */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): false { return false; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\BinaryBase\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -196,13 +186,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\BinaryBase\Value $value * - * @return mixed + * @return array|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { return [ 'id' => $value->id, @@ -216,7 +204,7 @@ public function toHash(SPIValue $value) ]; } - public function toPersistenceValue(SPIValue $value) + public function toPersistenceValue(SPIValue $value): PersistenceValue { // Store original data as external (to indicate they need to be stored) return new PersistenceValue( @@ -228,16 +216,7 @@ public function toPersistenceValue(SPIValue $value) ); } - /** - * Converts a persistence $fieldValue to a Value. - * - * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\BinaryBase\Value - */ - public function fromPersistenceValue(PersistenceValue $fieldValue) + public function fromPersistenceValue(PersistenceValue $fieldValue): SPIValue { // Restored data comes in $data, since it has already been processed // there might be more data in the persistence value than needed here @@ -263,14 +242,14 @@ public function fromPersistenceValue(PersistenceValue $fieldValue) /** * Validates a field based on the validators in the field definition. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field * @param \Ibexa\Core\FieldType\BinaryBase\Value $fieldValue The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array { $errors = []; @@ -318,7 +297,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -365,12 +344,7 @@ public function validateValidatorConfiguration($validatorConfiguration) return $validationErrors; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ - public function isSearchable() + public function isSearchable(): bool { return true; } diff --git a/src/lib/FieldType/BinaryBase/Value.php b/src/lib/FieldType/BinaryBase/Value.php index 8def62307b..cc4c77874a 100644 --- a/src/lib/FieldType/BinaryBase/Value.php +++ b/src/lib/FieldType/BinaryBase/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\BinaryBase; @@ -12,7 +13,7 @@ /** * Base value for binary field types. * - * @property string $path Used for BC with 5.0 (EZP-20948). Equivalent to $id. + * @property string $path Used for BC with legacy 5.0 (EZP-20948). Equivalent to $id. * @property-read string $id Unique file ID, set by storage. Read only since 5.3 (EZP-22808). */ abstract class Value extends BaseValue @@ -20,61 +21,59 @@ abstract class Value extends BaseValue /** * Unique file ID, set by storage. * - * Since 5.3 this is not used for input, use self::$inputUri instead + * Since legacy 5.3 this is not used for input, use self::$inputUri instead * * @var string|null */ - protected $id; + protected ?string $id = null; /** * Input file URI, as a path to a file on a disk. * * @var string|null */ - public $inputUri; + public ?string $inputUri = null; /** * Display file name. - * - * @var string|null */ - public $fileName; + public ?string $fileName = null; /** * Size of the image file. - * - * @var int|null */ - public $fileSize; + public ?int $fileSize = null; /** * Mime type of the file. - * - * @var string|null */ - public $mimeType; + public ?string $mimeType = null; /** * HTTP URI. - * - * @var string|null */ - public $uri; + public ?string $uri = null; /** - * Construct a new Value object. - * - * @param array $fileData + * @param array{ + * inputUri?: string|null, + * fileName?: string|null, + * fileSize?: int|null, + * mimeType?: string|null, + * uri?: string|null, + * id?: string|null, + * path?: string|null + * } $fileData */ public function __construct(array $fileData = []) { - // BC with 5.0 (EZP-20948) + // BC with legacy 5.0 (EZP-20948) if (isset($fileData['path'])) { $fileData['id'] = $fileData['path']; unset($fileData['path']); } - // BC with 5.2 (EZP-22808) + // BC with legacy 5.2 (EZP-22808) if (isset($fileData['id']) && file_exists($fileData['id'])) { $fileData['inputUri'] = $fileData['id']; unset($fileData['id']); @@ -85,15 +84,13 @@ public function __construct(array $fileData = []) /** * Returns a string representation of the field value. - * - * @return string */ - public function __toString() + public function __toString(): string { return (string)$this->uri; } - public function __get($propertyName) + public function __get($propertyName): mixed { if ($propertyName === 'path') { return $this->inputUri; @@ -102,7 +99,7 @@ public function __get($propertyName) return parent::__get($propertyName); } - public function __set($propertyName, $propertyValue) + public function __set($propertyName, $propertyValue): void { // BC with 5.0 (EZP-20948) if ($propertyName === 'path') { @@ -114,7 +111,7 @@ public function __set($propertyName, $propertyValue) } } - public function __isset($propertyName) + public function __isset($propertyName): bool { if ($propertyName === 'path') { return true; diff --git a/src/lib/FieldType/BinaryFile/Type.php b/src/lib/FieldType/BinaryFile/Type.php index fbcbd88ff7..147485281c 100644 --- a/src/lib/FieldType/BinaryFile/Type.php +++ b/src/lib/FieldType/BinaryFile/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\BinaryFile; @@ -31,13 +32,7 @@ public function getFieldTypeIdentifier(): string return 'ibexa_binaryfile'; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\BinaryFile\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -71,13 +66,9 @@ protected function completeValue(Basevalue $value) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\BinaryFile\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -90,26 +81,16 @@ public function toHash(SPIValue $value) return $hash; } - /** - * Converts a persistence $fieldValue to a Value. - * - * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\BinaryFile\Value - */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): SPIValue { if ($fieldValue->externalData === null) { return $this->getEmptyValue(); } + /** @var \Ibexa\Core\FieldType\BinaryFile\Value $result */ $result = parent::fromPersistenceValue($fieldValue); - $result->downloadCount = (isset($fieldValue->externalData['downloadCount']) - ? $fieldValue->externalData['downloadCount'] - : 0); + $result->downloadCount = (int)($fieldValue->externalData['downloadCount'] ?? 0); return $result; } diff --git a/src/lib/FieldType/BinaryFile/Value.php b/src/lib/FieldType/BinaryFile/Value.php index ae525c6e2b..3b51369fd6 100644 --- a/src/lib/FieldType/BinaryFile/Value.php +++ b/src/lib/FieldType/BinaryFile/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\BinaryFile; @@ -16,8 +17,6 @@ class Value extends BaseValue { /** * Number of times the file has been downloaded through content/download module. - * - * @var int */ - public $downloadCount = 0; + public int $downloadCount = 0; } diff --git a/src/lib/FieldType/Checkbox/Type.php b/src/lib/FieldType/Checkbox/Type.php index f66ea5570f..5ddbe69922 100644 --- a/src/lib/FieldType/Checkbox/Type.php +++ b/src/lib/FieldType/Checkbox/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Checkbox; @@ -40,13 +41,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $value->bool ? '1' : '0'; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Checkbox\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(false); } @@ -99,46 +94,26 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\Checkbox\Value $value - * - * @return int */ - protected function getSortInfo(BaseValue $value): int + protected function getSortInfo(SPIValue $value): int { return (int)$value->bool; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Checkbox\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value($hash); } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Checkbox\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): bool { return $value->bool; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/Checkbox/Value.php b/src/lib/FieldType/Checkbox/Value.php index a1339ee241..1c47280829 100644 --- a/src/lib/FieldType/Checkbox/Value.php +++ b/src/lib/FieldType/Checkbox/Value.php @@ -4,37 +4,23 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Checkbox; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Checkbox field type. + * Value for the Checkbox field type. */ class Value extends BaseValue { - /** - * Boolean value. - * - * @var bool - */ - public $bool; - - /** - * Construct a new Value object and initialize it $boolValue. - * - * @param bool $boolValue - */ - public function __construct($boolValue = false) + public function __construct(public readonly bool $bool = false) { - $this->bool = $boolValue; + parent::__construct(); } - /** - * @return string - */ - public function __toString() + public function __toString(): string { return $this->bool ? '1' : '0'; } diff --git a/src/lib/FieldType/Country/Type.php b/src/lib/FieldType/Country/Type.php index 3bbf49bb8e..f07d2682cd 100644 --- a/src/lib/FieldType/Country/Type.php +++ b/src/lib/FieldType/Country/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Country; @@ -24,7 +25,7 @@ */ class Type extends FieldType implements TranslationContainerInterface { - protected $settingsSchema = [ + protected array $settingsSchema = [ 'isMultiple' => [ 'type' => 'boolean', 'default' => false, @@ -60,13 +61,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Country\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -110,25 +105,25 @@ protected function checkValueStructure(BaseValue $value) * * Does not use validators. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\Country\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\Country\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $fieldSettings = $fieldDefinition->getFieldSettings(); + $fieldSettings = $fieldDef->getFieldSettings(); if ((!isset($fieldSettings['isMultiple']) || $fieldSettings['isMultiple'] === false) - && count($fieldValue->countries) > 1) { + && count($value->countries) > 1) { $validationErrors[] = new ValidationError( 'Field definition does not allow multiple countries to be selected.', null, @@ -137,7 +132,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - foreach ($fieldValue->countries as $alpha2 => $countryInfo) { + foreach ($value->countries as $alpha2 => $countryInfo) { if (!isset($this->countriesInfo[$alpha2])) { $validationErrors[] = new ValidationError( "Country with Alpha2 code '%alpha2%' is not defined in FieldType settings.", @@ -154,9 +149,9 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } /** - * {@inheritdoc} + * @param \Ibexa\Core\FieldType\Country\Value $value */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { $countries = []; foreach ($value->countries as $countryInfo) { @@ -168,14 +163,7 @@ protected function getSortInfo(BaseValue $value): string return implode(',', $countries); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Country\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -200,13 +188,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Country\Value $value * - * @return mixed + * @return string[]|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -215,24 +201,12 @@ public function toHash(SPIValue $value) return array_keys($value->countries); } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/Country/Value.php b/src/lib/FieldType/Country/Value.php index d72e0c44a1..f9aaf12f57 100644 --- a/src/lib/FieldType/Country/Value.php +++ b/src/lib/FieldType/Country/Value.php @@ -4,46 +4,40 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Country; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Country field type. + * Value for a Country field type. + * + * @phpstan-type TCountriesHash array */ class Value extends BaseValue { /** - * Associative array with Alpha2 codes as keys and countries data as values. + * @phpstan-param TCountriesHash $countries * - * Example: - * - * array( - * "JP" => array( - * "Name" => "Japan", - * "Alpha2" => "JP", - * "Alpha3" => "JPN", - * "IDC" => 81 - * ) - * ) - * - * - * @var array[] - */ - public $countries = []; - - /** - * Construct a new Value object and initialize it with given $data. - * - * @param array[] $countries + * Example Country hash entry: + * ``` + * [ + * "JP" => [ + * "Name" => "Japan", + * "Alpha2" => "JP", + * "Alpha3" => "JPN", + * "IDC" => 81 + * ] + * ] + * ``` */ - public function __construct(array $countries = []) + public function __construct(public readonly array $countries = []) { - $this->countries = $countries; + parent::__construct(); } - public function __toString() + public function __toString(): string { return implode(', ', array_column($this->countries, 'Name')); } diff --git a/src/lib/FieldType/Date/Type.php b/src/lib/FieldType/Date/Type.php index f7f2f5fa7b..d7ecc1ec39 100644 --- a/src/lib/FieldType/Date/Type.php +++ b/src/lib/FieldType/Date/Type.php @@ -4,10 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Date; use DateTime; +use DateTimeInterface; use Ibexa\Contracts\Core\FieldType\Value as SPIValue; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; @@ -29,7 +31,7 @@ class Type extends FieldType implements TranslationContainerInterface */ public const DEFAULT_CURRENT_DATE = 1; - protected $settingsSchema = [ + protected array $settingsSchema = [ // One of the DEFAULT_* class constants 'defaultType' => [ 'type' => 'choice', @@ -59,13 +61,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $value->date->format('l d F Y'); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Date\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -113,32 +109,22 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\Date\Value $value - * - * @return mixed */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): int|null { - if ($value->date === null) { - return null; - } - - return $value->date->getTimestamp(); + return $value->date?->getTimestamp(); } /** - * Converts an $hash to the Value defined by the field type. - * * @param mixed $hash Null or associative array containing one of the following (first value found in the order below is picked): * 'rfc850': Date in RFC 850 format (DateTime::RFC850) * 'timestring': Date in parseable string format supported by DateTime (e.g. 'now', '+3 days') * 'timestamp': Unix timestamp * - * @return \Ibexa\Core\FieldType\Date\Value $value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -156,13 +142,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Date\Value $value * - * @return mixed + * @return array{timestamp: int, rfc850: string|null}|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -171,7 +155,7 @@ public function toHash(SPIValue $value) if ($value->date instanceof DateTime) { return [ 'timestamp' => $value->date->getTimestamp(), - 'rfc850' => $value->date->format(DateTime::RFC850), + 'rfc850' => $value->date->format(DateTimeInterface::RFC850), ]; } @@ -181,24 +165,12 @@ public function toHash(SPIValue $value) ]; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/Date/Value.php b/src/lib/FieldType/Date/Value.php index 62b46e7885..d70be89bd4 100644 --- a/src/lib/FieldType/Date/Value.php +++ b/src/lib/FieldType/Date/Value.php @@ -4,86 +4,72 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Date; use DateTime; +use DateTimeInterface; use DateTimeZone; use Exception; use Ibexa\Core\Base\Exceptions\InvalidArgumentValue; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Date field type. + * Value for the Date field type. * Date should always be represented in UTC. */ class Value extends BaseValue { /** * Date content. - * - * @var \DateTime|null */ - public $date; + public readonly ?DateTimeInterface $date; /** * Date format to be used by {@link __toString()}. - * - * @var string */ - public $stringFormat = 'l d F Y'; + public string $stringFormat = 'l d F Y'; /** - * Construct a new Value object and initialize with $dateTime. - * * @param \DateTime|null $dateTime Date as a DateTime object */ - public function __construct(DateTime $dateTime = null) + public function __construct(?DateTimeInterface $dateTime = null) { if ($dateTime !== null) { $dateTime = clone $dateTime; $dateTime->setTime(0, 0, 0); } $this->date = $dateTime; + + parent::__construct(); } /** - * Creates a Value from the given $dateString. - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param string $dateString - * - * @return \Ibexa\Core\FieldType\Date\Value */ - public static function fromString($dateString) + public static function fromString(string $dateString): Value { try { - return new static(new DateTime($dateString, new DateTimeZone('UTC'))); + return new self(new DateTime($dateString, new DateTimeZone('UTC'))); } catch (Exception $e) { throw new InvalidArgumentValue('$dateString', $dateString, __CLASS__, $e); } } /** - * Creates a Value from the given $timestamp. - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param int $timestamp - * - * @return \Ibexa\Core\FieldType\Date\Value */ - public static function fromTimestamp($timestamp) + public static function fromTimestamp(int $timestamp): Value { try { - return new static(new DateTime("@{$timestamp}")); + return new self(new DateTime("@{$timestamp}")); } catch (Exception $e) { throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e); } } - public function __toString() + public function __toString(): string { if (!$this->date instanceof DateTime) { return ''; diff --git a/src/lib/FieldType/DateAndTime/Type.php b/src/lib/FieldType/DateAndTime/Type.php index 1383c106a6..61026088e1 100644 --- a/src/lib/FieldType/DateAndTime/Type.php +++ b/src/lib/FieldType/DateAndTime/Type.php @@ -4,11 +4,13 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\DateAndTime; use DateInterval; use DateTime; +use DateTimeInterface; use Ibexa\Contracts\Core\FieldType\Value as SPIValue; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; @@ -27,7 +29,7 @@ class Type extends FieldType implements TranslationContainerInterface public const DEFAULT_CURRENT_DATE = 1; public const DEFAULT_CURRENT_DATE_ADJUSTED = 2; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'useSeconds' => [ 'type' => 'bool', 'default' => false, @@ -69,13 +71,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $value->value->format('D Y-d-m H:i:s'); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\DateAndTime\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -123,32 +119,20 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\DateAndTime\Value $value - * - * @return int|null */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): int|null { - if ($value->value === null) { - return null; - } - - return $value->value->getTimestamp(); + return $value->value?->getTimestamp(); } /** - * Converts an $hash to the Value defined by the field type. - * * @param mixed $hash Null or associative array containing one of the following (first value found in the order below is picked): * 'rfc850': Date in RFC 850 format (DateTime::RFC850) * 'timestring': Date in parseable string format supported by DateTime (e.g. 'now', '+3 days') * 'timestamp': Unix timestamp - * - * @return \Ibexa\Core\FieldType\DateAndTime\Value $value */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -166,13 +150,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\DateAndTime\Value $value * - * @return mixed + * @return array{timestamp: int, rfc850: string|null}|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -181,7 +163,7 @@ public function toHash(SPIValue $value) if ($value->value instanceof DateTime) { return [ 'timestamp' => $value->value->getTimestamp(), - 'rfc850' => $value->value->format(DateTime::RFC850), + 'rfc850' => $value->value->format(DateTimeInterface::RFC850), ]; } @@ -191,24 +173,12 @@ public function toHash(SPIValue $value) ]; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -289,9 +259,9 @@ public function validateFieldSettings($fieldSettings) * * @param mixed $fieldSettings * - * @return array|scalar|null + * @return mixed */ - public function fieldSettingsToHash($fieldSettings) + public function fieldSettingsToHash(mixed $fieldSettings): mixed { $fieldSettingsHash = parent::fieldSettingsToHash($fieldSettings); @@ -314,11 +284,11 @@ public function fieldSettingsToHash($fieldSettings) * a hash format. Overwrite this in your specific implementation, if * necessary. * - * @param array|scalar|null $fieldSettingsHash + * @param mixed $fieldSettingsHash * * @return mixed */ - public function fieldSettingsFromHash($fieldSettingsHash) + public function fieldSettingsFromHash(mixed $fieldSettingsHash): mixed { $fieldSettings = parent::fieldSettingsFromHash($fieldSettingsHash); diff --git a/src/lib/FieldType/DateAndTime/Value.php b/src/lib/FieldType/DateAndTime/Value.php index fe9865df65..f7e44334c1 100644 --- a/src/lib/FieldType/DateAndTime/Value.php +++ b/src/lib/FieldType/DateAndTime/Value.php @@ -4,78 +4,70 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\DateAndTime; use DateTime; +use DateTimeInterface; use Exception; use Ibexa\Core\Base\Exceptions\InvalidArgumentValue; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for DateAndTime field type. + * Value for the DateAndTime field type. */ class Value extends BaseValue { /** * Date content. - * - * @var \DateTime|null */ - public $value; + public readonly ?DateTimeInterface $value; /** * Date format to be used by {@link __toString()}. - * - * @var string */ - public $stringFormat = 'U'; + public string $stringFormat = 'U'; /** * Construct a new Value object and initialize with $dateTime. * * @param \DateTime|null $dateTime Date/Time as a DateTime object */ - public function __construct(DateTime $dateTime = null) + public function __construct(?DateTimeInterface $dateTime = null) { $this->value = $dateTime; + + parent::__construct(); } /** - * Creates a Value from the given $dateString. - * - * @param string $dateString - * - * @return \Ibexa\Core\FieldType\DateAndTime\Value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public static function fromString($dateString) + public static function fromString(string $dateString): Value { try { - return new static(new DateTime($dateString)); + return new self(new DateTime($dateString)); } catch (Exception $e) { throw new InvalidArgumentValue('$dateString', $dateString, __CLASS__, $e); } } /** - * Creates a Value from the given $timestamp. - * - * @param int $timestamp - * - * @return \Ibexa\Core\FieldType\DateAndTime\Value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public static function fromTimestamp($timestamp) + public static function fromTimestamp(int $timestamp): Value { try { - return new static(new DateTime("@{$timestamp}")); + return new self(new DateTime("@$timestamp")); } catch (Exception $e) { throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e); } } - public function __toString() + public function __toString(): string { - if (!$this->value instanceof DateTime) { + if (null === $this->value) { return ''; } diff --git a/src/lib/FieldType/EmailAddress/Type.php b/src/lib/FieldType/EmailAddress/Type.php index 0c16672915..c6ee55eb71 100644 --- a/src/lib/FieldType/EmailAddress/Type.php +++ b/src/lib/FieldType/EmailAddress/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\EmailAddress; @@ -24,7 +25,7 @@ */ class Type extends FieldType implements TranslationContainerInterface { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'EmailAddressValidator' => [], ]; @@ -43,7 +44,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; $validator = new EmailAddressValidator(); @@ -69,29 +70,29 @@ public function validateValidatorConfiguration($validatorConfiguration) /** * Validates a field based on the validators in the field definition. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\EmailAddress\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\EmailAddress\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $errors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $errors; } - $validatorConfiguration = $fieldDefinition->getValidatorConfiguration(); + $validatorConfiguration = $fieldDef->getValidatorConfiguration(); $constraints = isset($validatorConfiguration['EmailAddressValidator']) ? $validatorConfiguration['EmailAddressValidator'] : []; $validator = new EmailAddressValidator(); $validator->initializeWithConstraints($constraints); - if (!$validator->validate($fieldValue)) { + if (!$validator->validate($value)) { return $validator->getMessage(); } @@ -108,13 +109,7 @@ public function getFieldTypeIdentifier(): string return 'ibexa_email'; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\EmailAddress\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -154,27 +149,16 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * - * @todo String normalization should occur here. - * * @param \Ibexa\Core\FieldType\EmailAddress\Value $value * - * @return string + * @todo String normalization should occur here. */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): string { return $value->email; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\EmailAddress\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -184,13 +168,9 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\EmailAddress\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?string { if ($this->isEmptyValue($value)) { return null; @@ -199,11 +179,6 @@ public function toHash(SPIValue $value) return $value->email; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/EmailAddress/Value.php b/src/lib/FieldType/EmailAddress/Value.php index c7ac67a44c..b5a2d8fca5 100644 --- a/src/lib/FieldType/EmailAddress/Value.php +++ b/src/lib/FieldType/EmailAddress/Value.php @@ -4,35 +4,27 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\EmailAddress; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for EMailAddress field type. + * Value for the EmailAddress field type. */ class Value extends BaseValue { - /** - * Email address. - * - * @var string - */ - public $email; - /** * Construct a new Value object and initialize its $email. - * - * @param string $email */ - public function __construct($email = '') + public function __construct(public readonly string $email = '') { - $this->email = $email; + parent::__construct(); } - public function __toString() + public function __toString(): string { - return (string)$this->email; + return $this->email; } } diff --git a/src/lib/FieldType/FieldType.php b/src/lib/FieldType/FieldType.php index 6414b4d118..ecf587e81f 100644 --- a/src/lib/FieldType/FieldType.php +++ b/src/lib/FieldType/FieldType.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType; @@ -40,9 +41,9 @@ abstract class FieldType extends SPIFieldType implements Comparable * The key is the setting name, and the value is the default value for given * setting, set to null if no particular default should be set. * - * @var mixed + * @var array */ - protected $settingsSchema = []; + protected array $settingsSchema = []; /** * The validator configuration schema. @@ -53,9 +54,9 @@ abstract class FieldType extends SPIFieldType implements Comparable * * @see getValidatorConfigurationSchema() * - * @var mixed + * @var array */ - protected $validatorConfigurationSchema = []; + protected array $validatorConfigurationSchema = []; /** * String transformation processor, used to normalize sort string as needed. @@ -78,10 +79,8 @@ public function setTransformationProcessor(TransformationProcessor $transformati * This implementation returns an array. * where the key is the setting name, and the value is the default value for given * setting and set to null if no particular default should be set. - * - * @return mixed */ - public function getSettingsSchema() + public function getSettingsSchema(): array { return $this->settingsSchema; } @@ -89,30 +88,28 @@ public function getSettingsSchema() /** * Returns a schema for the validator configuration expected by the FieldType. * - * @see FieldTypeInterface::getValidatorConfigurationSchema() + * @see \Ibexa\Contracts\Core\FieldType\FieldType::getValidatorConfigurationSchema() * - * This implementation returns a three dimensional map containing for each validator configuration + * This implementation returns a three-dimensional map containing for each validator configuration * referenced by identifier a map of supported parameters which are defined by a type and a default value * (see example). * - * - * array( - * 'stringLength' => array( - * 'minStringLength' => array( + * ``` + * [ + * 'stringLength' => [ + * 'minStringLength' => [ * 'type' => 'int', * 'default' => 0, - * ), - * 'maxStringLength' => array( + * ], + * 'maxStringLength' => [ * 'type' => 'int' * 'default' => null, - * ) - * ), - * ); - * - * - * @return mixed + * ] + * ], + * ]; + * ``` */ - public function getValidatorConfigurationSchema() + public function getValidatorConfigurationSchema(): array { return $this->validatorConfigurationSchema; } @@ -124,14 +121,14 @@ public function getValidatorConfigurationSchema() * that no validation errors occurred. Overwrite in derived types, if * validation is supported. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field * @param \Ibexa\Core\FieldType\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $value) + public function validate(FieldDefinition $fieldDefinition, SPIValue $value): array { return []; } @@ -150,7 +147,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value) * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -178,7 +175,7 @@ public function validateValidatorConfiguration($validatorConfiguration) * * @param mixed $validatorConfiguration */ - public function applyDefaultValidatorConfiguration(&$validatorConfiguration) + public function applyDefaultValidatorConfiguration(mixed &$validatorConfiguration): void { if ($validatorConfiguration !== null && !is_array($validatorConfiguration)) { throw new InvalidArgumentType('$validatorConfiguration', 'array|null', $validatorConfiguration); @@ -204,12 +201,8 @@ public function applyDefaultValidatorConfiguration(&$validatorConfiguration) * * This method expects that given $fieldSettings are complete, for this purpose method * {@link self::applyDefaultSettings()} is provided. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { if (!empty($fieldSettings)) { return [ @@ -228,24 +221,16 @@ public function validateFieldSettings($fieldSettings) } /** - * Applies the default values to the fieldSettings of a FieldDefinitionCreateStruct. + * {@inheritDoc} * * This is a base implementation, expecting best practice field settings format used by * field types in standard Ibexa installation. Overwrite in derived types if needed. - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param mixed $fieldSettings */ - public function applyDefaultSettings(&$fieldSettings) + public function applyDefaultSettings(array &$fieldSettings): void { - if ($fieldSettings !== null && !is_array($fieldSettings)) { - throw new InvalidArgumentType('$fieldSettings', 'array|null', $fieldSettings); - } - foreach ($this->getSettingsSchema() as $settingName => $settingConfiguration) { // Checking that a default entry exists in the settingsSchema but that no value has been provided - if (!array_key_exists($settingName, (array)$fieldSettings) && array_key_exists('default', $settingConfiguration)) { + if (!array_key_exists($settingName, $fieldSettings) && array_key_exists('default', $settingConfiguration)) { $fieldSettings[$settingName] = $settingConfiguration['default']; } } @@ -254,34 +239,22 @@ public function applyDefaultSettings(&$fieldSettings) /** * Returns information for FieldValue->$sortKey relevant to the field type. * - * Return value is mixed. It should be something which is sensible for - * sorting. + * The return value is mixed. It should be a scalar that is sensible for sorting. * * It is up to the persistence implementation to handle those values. * Common string and integer values are safe. * - * For the legacy storage it is up to the field converters to set this + * For the legacy storage, it is up to the field converters to set this * value in either sort_key_string or sort_key_int. * - * In case of multi value, values should be string and separated by "-" or ",". - * - * @param \Ibexa\Core\FieldType\Value $value - * - * @return mixed + * In the case of multi-value, values should be string and separated by "-" or ",". */ - protected function getSortInfo(Value $value) + protected function getSortInfo(SPIValue $value): mixed { return null; } - /** - * Converts a $value to a persistence value. - * - * @param \Ibexa\Core\FieldType\Value $value - * - * @return \Ibexa\Contracts\Core\Persistence\Content\FieldValue - */ - public function toPersistenceValue(SPIValue $value) + public function toPersistenceValue(SPIValue $value): PersistenceValue { // @todo Evaluate if creating the sortKey in every case is really needed // Couldn't this be retrieved with a method, which would initialize @@ -295,86 +268,32 @@ public function toPersistenceValue(SPIValue $value) ); } - /** - * Converts a persistence $fieldValue to a Value. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\Value - */ - public function fromPersistenceValue(PersistenceValue $fieldValue) + public function fromPersistenceValue(PersistenceValue $fieldValue): SPIValue { return $this->fromHash($fieldValue->data); } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ - public function isSearchable() + public function isSearchable(): bool { return false; } - /** - * Indicates if the field definition of this type can appear only once in the same ContentType. - * - * @return bool - */ - public function isSingular() + public function isSingular(): bool { return false; } - /** - * Indicates if the field definition of this type can be added to a ContentType with Content instances. - * - * @return bool - */ - public function onlyEmptyInstance() + public function onlyEmptyInstance(): bool { return false; } - /** - * Returns if the given $value is considered empty by the field type. - * - * Default implementation, which performs a "==" check with the value - * returned by {@link getEmptyValue()}. Overwrite in the specific field - * type, if necessary. - * - * @param \Ibexa\Core\FieldType\Value $value - * - * @return bool - */ - public function isEmptyValue(SPIValue $value) + public function isEmptyValue(SPIValue $value): bool { return $value == $this->getEmptyValue(); } - /** - * Potentially builds and checks the type and structure of the $inputValue. - * - * This method first inspects $inputValue and convert it into a dedicated - * value object. - * - * After that, the value is checked for structural validity. - * Note that this does not include validation after the rules - * from validators, but only plausibility checks for the general data - * format. - * - * Note that this method must also cope with the empty value for the field - * type as e.g. returned by {@link getEmptyValue()}. - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if the parameter is not of the supported value sub type - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if the value does not match the expected structure - * - * @param mixed $inputValue - * - * @return \Ibexa\Core\FieldType\Value The potentially converted and structurally plausible value. - */ - final public function acceptValue($inputValue) + final public function acceptValue(mixed $inputValue): SPIValue { if ($inputValue === null) { return $this->getEmptyValue(); @@ -488,9 +407,9 @@ abstract protected function checkValueStructure(Value $value); * * @param mixed $fieldSettings * - * @return array|scalar|null + * @return mixed */ - public function fieldSettingsToHash($fieldSettings) + public function fieldSettingsToHash(mixed $fieldSettings): mixed { return $fieldSettings; } @@ -505,11 +424,11 @@ public function fieldSettingsToHash($fieldSettings) * a hash format. Overwrite this in your specific implementation, if * necessary. * - * @param array|scalar|null $fieldSettingsHash + * @param mixed $fieldSettingsHash * * @return mixed */ - public function fieldSettingsFromHash($fieldSettingsHash) + public function fieldSettingsFromHash(mixed $fieldSettingsHash): mixed { return $fieldSettingsHash; } @@ -523,9 +442,9 @@ public function fieldSettingsFromHash($fieldSettingsHash) * * @param mixed $validatorConfiguration * - * @return array|scalar|null + * @return mixed */ - public function validatorConfigurationToHash($validatorConfiguration) + public function validatorConfigurationToHash(mixed $validatorConfiguration): mixed { return $validatorConfiguration; } @@ -539,41 +458,16 @@ public function validatorConfigurationToHash($validatorConfiguration) * convention an array for all internal field types. Overwrite this method, * if necessary. * - * @param array|scalar|null $validatorConfigurationHash + * @param mixed $validatorConfigurationHash * * @return mixed */ - public function validatorConfigurationFromHash($validatorConfigurationHash) + public function validatorConfigurationFromHash(mixed $validatorConfigurationHash): mixed { return $validatorConfigurationHash; } - /** - * Returns relation data extracted from value. - * - * Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, - * there is an API for handling those. - * - * @param \Ibexa\Core\FieldType\Value $fieldValue - * - * @return array Hash with relation type as key and array of destination content ids as value. - * - * Example: - * - * array( - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => array( - * "contentIds" => array( 12, 13, 14 ), - * "locationIds" => array( 24 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => array( - * "contentIds" => array( 12 ), - * "locationIds" => array( 24, 45 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => array( 12 ) - * ) - * - */ - public function getRelations(SPIValue $fieldValue) + public function getRelations(SPIValue $fieldValue): array { return []; } diff --git a/src/lib/FieldType/Float/Type.php b/src/lib/FieldType/Float/Type.php index 71bb1c1d01..4a8832f5ed 100644 --- a/src/lib/FieldType/Float/Type.php +++ b/src/lib/FieldType/Float/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Float; @@ -23,7 +24,7 @@ */ class Type extends BaseNumericType implements TranslationContainerInterface { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'FloatValueValidator' => [ 'minFloatValue' => [ 'type' => 'float', @@ -59,10 +60,6 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - */ public function getEmptyValue(): Value { return new Value(); @@ -112,23 +109,14 @@ protected function checkValueStructure(BaseValue $value): void } /** - * {@inheritdoc} - * * @param \Ibexa\Core\FieldType\Float\Value $value */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): ?float { return $value->value; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Float\Value $value - */ - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -138,13 +126,9 @@ public function fromHash($hash): Value } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Float\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value): mixed + public function toHash(SPIValue $value): ?float { if ($this->isEmptyValue($value)) { return null; diff --git a/src/lib/FieldType/Float/Value.php b/src/lib/FieldType/Float/Value.php index fd79d55c9c..ecfb78cae0 100644 --- a/src/lib/FieldType/Float/Value.php +++ b/src/lib/FieldType/Float/Value.php @@ -4,34 +4,23 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Float; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Float field type. + * Value for the Float field type. */ class Value extends BaseValue { - /** - * Float content. - * - * @var float|null - */ - public $value; - - /** - * Construct a new Value object and initialize with $value. - * - * @param float|null $value - */ - public function __construct($value = null) + public function __construct(public readonly ?float $value = null) { - $this->value = $value; + parent::__construct(); } - public function __toString() + public function __toString(): string { return (string)$this->value; } diff --git a/src/lib/FieldType/ISBN/Type.php b/src/lib/FieldType/ISBN/Type.php index 3f17ed6a7e..8abc0ee613 100644 --- a/src/lib/FieldType/ISBN/Type.php +++ b/src/lib/FieldType/ISBN/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\ISBN; @@ -29,7 +30,7 @@ class Type extends FieldType implements TranslationContainerInterface public const ISBN13_PREFIX_978 = '978'; public const ISBN13_PREFIX_979 = '979'; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'isISBN13' => [ 'type' => 'boolean', 'default' => true, @@ -56,23 +57,13 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value->isbn; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\ISBN\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } /** - * Returns if the given $value is considered empty by the field type. - * - * @param mixed $value - * - * @return bool + * @param \Ibexa\Core\FieldType\ISBN\Value $value */ public function isEmptyValue(SPIValue $value): bool { @@ -118,22 +109,22 @@ protected function checkValueStructure(BaseValue $value) * * Does not use validators. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\ISBN\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\ISBN\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $fieldSettings = $fieldDefinition->getFieldSettings(); - $isbnTestNumber = preg_replace("/[\s|\-]/", '', trim($fieldValue->isbn)); + $fieldSettings = $fieldDef->getFieldSettings(); + $isbnTestNumber = preg_replace("/[\s|\-]/", '', trim($value->isbn)); // Check if value and settings are inline if ((!isset($fieldSettings['isISBN13']) || $fieldSettings['isISBN13'] === false) @@ -170,25 +161,14 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\ISBN\Value $value - * - * @return string */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): string { return $this->transformationProcessor->transformByGroup((string)$value, 'lowercase'); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\ISBN\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null || $hash === '') { return $this->getEmptyValue(); @@ -198,13 +178,9 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\ISBN\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?string { if ($this->isEmptyValue($value)) { return null; @@ -213,24 +189,12 @@ public function toHash(SPIValue $value) return $value->isbn; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/ISBN/Value.php b/src/lib/FieldType/ISBN/Value.php index 7b260ba7c1..dc28f71bda 100644 --- a/src/lib/FieldType/ISBN/Value.php +++ b/src/lib/FieldType/ISBN/Value.php @@ -4,35 +4,24 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\ISBN; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for ISBN field type. + * Value for the ISBN field type. */ class Value extends BaseValue { - /** - * ISBN content. - * - * @var string - */ - public $isbn; - - /** - * Construct a new Value object and initialize it with its $isbn. - * - * @param string $isbn - */ - public function __construct($isbn = '') + public function __construct(public readonly string $isbn = '') { - $this->isbn = $isbn; + parent::__construct(); } - public function __toString() + public function __toString(): string { - return (string)$this->isbn; + return $this->isbn; } } diff --git a/src/lib/FieldType/Image/AliasCleanerInterface.php b/src/lib/FieldType/Image/AliasCleanerInterface.php index 6a41c6c01d..693e4296ef 100644 --- a/src/lib/FieldType/Image/AliasCleanerInterface.php +++ b/src/lib/FieldType/Image/AliasCleanerInterface.php @@ -16,6 +16,9 @@ interface AliasCleanerInterface * Removes all aliases corresponding to original image. * * @param string $originalPath Path to original image which aliases have been created from. - */ - public function removeAliases($originalPath); + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * */ + public function removeAliases(string $originalPath): void; } diff --git a/src/lib/FieldType/Image/IO/Legacy.php b/src/lib/FieldType/Image/IO/Legacy.php index f4e691cc98..70db0d8cac 100644 --- a/src/lib/FieldType/Image/IO/Legacy.php +++ b/src/lib/FieldType/Image/IO/Legacy.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Image\IO; @@ -25,42 +26,35 @@ * and on exception, will fall back to the draft IOService. * * In addition, loadBinaryFile() will also hide the need to explicitly call getExternalPath() - * on the internal path stored in legacy. + * on the internal path stored in legacy. + * + * @internal */ class Legacy implements IOServiceInterface { /** * Published images IO Service. - * - * @var \Ibexa\Core\IO\IOServiceInterface */ - private $publishedIOService; + private IOServiceInterface $publishedIOService; /** * Draft images IO Service. - * - * @var \Ibexa\Core\IO\IOServiceInterface */ - private $draftIOService; + private IOServiceInterface $draftIOService; /** * Prefix for published images. * Example: var/ibexa_demo_site/storage/images. - * - * @var string */ - private $publishedPrefix; + private string $publishedPrefix; /** * Prefix for draft images. * Example: var/ibexa_demo_site/storage/images-versioned. - * - * @var string */ - private $draftPrefix; + private string $draftPrefix; - /** @var \Ibexa\Core\FieldType\Image\IO\OptionsProvider */ - private $optionsProvider; + private OptionsProvider $optionsProvider; /** * @param \Ibexa\Core\FieldType\Image\IO\OptionsProvider $optionsProvider Path options. Known keys: var_dir, storage_dir, draft_images_dir, published_images_dir. @@ -70,8 +64,11 @@ class Legacy implements IOServiceInterface * @throws \Symfony\Component\OptionsResolver\Exception\MissingOptionsException * If a required option is missing. */ - public function __construct(IOServiceInterface $publishedIOService, IOServiceInterface $draftIOService, OptionsProvider $optionsProvider) - { + public function __construct( + IOServiceInterface $publishedIOService, + IOServiceInterface $draftIOService, + OptionsProvider $optionsProvider + ) { $this->publishedIOService = $publishedIOService; $this->draftIOService = $draftIOService; $this->optionsProvider = $optionsProvider; @@ -81,7 +78,7 @@ public function __construct(IOServiceInterface $publishedIOService, IOServiceInt /** * Sets the IOService prefix. */ - public function setPrefix($prefix) + public function setPrefix(string $prefix): void { $this->publishedIOService->setPrefix($prefix); $this->draftIOService->setPrefix($prefix); @@ -90,7 +87,7 @@ public function setPrefix($prefix) /** * Computes the paths to published & draft images path using the options from the provider. */ - private function setPrefixes() + private function setPrefixes(): void { $pathArray = [$this->optionsProvider->getVarDir()]; @@ -103,17 +100,17 @@ private function setPrefixes() $this->publishedPrefix = implode('/', array_merge($pathArray, [$this->optionsProvider->getPublishedImagesDir()])); } - public function newBinaryCreateStructFromLocalFile($localFile) + public function newBinaryCreateStructFromLocalFile(string $localFile): BinaryFileCreateStruct { return $this->publishedIOService->newBinaryCreateStructFromLocalFile($localFile); } - public function exists($binaryFileId) + public function exists(string $binaryFileId): bool { return $this->publishedIOService->exists($binaryFileId); } - public function loadBinaryFile($binaryFileId) + public function loadBinaryFile(string $binaryFileId): BinaryFile { // If the id is an internal (absolute) path to a draft image, use the draft service to get external path & load if ($this->isDraftImagePath($binaryFileId)) { @@ -145,8 +142,10 @@ public function loadBinaryFile($binaryFileId) /** * Since both services should use the same uri, we can use any of them to *GET* the URI. + * + * {@inheritDoc} */ - public function loadBinaryFileByUri($binaryFileUri) + public function loadBinaryFileByUri(string $binaryFileUri): BinaryFile { try { $image = $this->publishedIOService->loadBinaryFileByUri($binaryFileUri); @@ -166,7 +165,7 @@ public function loadBinaryFileByUri($binaryFileUri) } } - public function getFileContents(BinaryFile $binaryFile) + public function getFileContents(BinaryFile $binaryFile): string { if ($this->draftIOService->exists($binaryFile->id)) { return $this->draftIOService->getFileContents($binaryFile); @@ -175,17 +174,17 @@ public function getFileContents(BinaryFile $binaryFile) return $this->publishedIOService->getFileContents($binaryFile); } - public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) + public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct): BinaryFile { return $this->publishedIOService->createBinaryFile($binaryFileCreateStruct); } - public function getUri($binaryFileId) + public function getUri(string $binaryFileId): string { return $this->publishedIOService->getUri($binaryFileId); } - public function getMimeType($binaryFileId) + public function getMimeType(string $binaryFileId): ?string { // If the id is an internal (absolute) path to a draft image, use the draft service to get external path & load if ($this->isDraftImagePath($binaryFileId)) { @@ -206,12 +205,12 @@ public function getMimeType($binaryFileId) return $this->publishedIOService->getMimeType($binaryFileId); } - public function getFileInputStream(BinaryFile $binaryFile) + public function getFileInputStream(BinaryFile $binaryFile): mixed { return $this->publishedIOService->getFileInputStream($binaryFile); } - public function deleteBinaryFile(BinaryFile $binaryFile) + public function deleteBinaryFile(BinaryFile $binaryFile): void { $this->publishedIOService->deleteBinaryFile($binaryFile); } @@ -221,12 +220,12 @@ public function deleteBinaryFile(BinaryFile $binaryFile) * * @param string $path */ - public function deleteDirectory($path) + public function deleteDirectory(string $path): void { $this->publishedIOService->deleteDirectory($path); } - public function newBinaryCreateStructFromUploadedFile(array $uploadedFile) + public function newBinaryCreateStructFromUploadedFile(array $uploadedFile): BinaryFileCreateStruct { return $this->publishedIOService->newBinaryCreateStructFromUploadedFile($uploadedFile); } @@ -234,24 +233,20 @@ public function newBinaryCreateStructFromUploadedFile(array $uploadedFile) /** * Checks if $internalPath is a published image path. * - * @param string $internalPath - * * @return bool true if $internalPath is the path to a published image */ - protected function isPublishedImagePath($internalPath): bool + protected function isPublishedImagePath(string $internalPath): bool { - return strpos($internalPath, $this->publishedPrefix) === 0; + return str_starts_with($internalPath, $this->publishedPrefix); } /** - * Checks if $internalPath is a published image path. + * Checks if $internalPath is a draft image path. * - * @param string $internalPath - * - * @return bool true if $internalPath is the path to a published image + * @return bool true if $internalPath is the path to a draft image */ - protected function isDraftImagePath($internalPath): bool + protected function isDraftImagePath(string $internalPath): bool { - return strpos($internalPath, $this->draftPrefix) === 0; + return str_starts_with($internalPath, $this->draftPrefix); } } diff --git a/src/lib/FieldType/Image/IO/OptionsProvider.php b/src/lib/FieldType/Image/IO/OptionsProvider.php index 767bbba442..ad13e8efdf 100644 --- a/src/lib/FieldType/Image/IO/OptionsProvider.php +++ b/src/lib/FieldType/Image/IO/OptionsProvider.php @@ -14,8 +14,7 @@ */ class OptionsProvider { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - protected $configResolver; + protected ConfigResolverInterface $configResolver; public function __construct(ConfigResolverInterface $configResolver) { @@ -29,22 +28,22 @@ protected function getSetting(string $name): ?string : null; } - public function getVarDir() + public function getVarDir(): ?string { return $this->getSetting('var_dir'); } - public function getStorageDir() + public function getStorageDir(): ?string { return $this->getSetting('storage_dir'); } - public function getDraftImagesDir() + public function getDraftImagesDir(): ?string { return $this->getSetting('image.versioned_images_dir'); } - public function getPublishedImagesDir() + public function getPublishedImagesDir(): ?string { return $this->getSetting('image.published_images_dir'); } diff --git a/src/lib/FieldType/Image/NullAliasCleaner.php b/src/lib/FieldType/Image/NullAliasCleaner.php index f3ffb523b3..dfcb6d5d76 100644 --- a/src/lib/FieldType/Image/NullAliasCleaner.php +++ b/src/lib/FieldType/Image/NullAliasCleaner.php @@ -18,7 +18,7 @@ */ final class NullAliasCleaner implements AliasCleanerInterface { - public function removeAliases($originalPath): void + public function removeAliases(string $originalPath): void { // Nothing to do } diff --git a/src/lib/FieldType/Image/Type.php b/src/lib/FieldType/Image/Type.php index 90fa8fb0cc..7b869122ec 100644 --- a/src/lib/FieldType/Image/Type.php +++ b/src/lib/FieldType/Image/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Image; @@ -22,7 +23,7 @@ */ class Type extends FieldType implements TranslationContainerInterface { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'FileSizeValidator' => [ 'maxFileSize' => [ 'type' => 'numeric', @@ -45,7 +46,7 @@ class Type extends FieldType implements TranslationContainerInterface * } * } */ - protected $settingsSchema = [ + protected array $settingsSchema = [ 'mimeTypes' => [ 'type' => 'choice', 'default' => [], @@ -53,7 +54,7 @@ class Type extends FieldType implements TranslationContainerInterface ]; /** @var \Ibexa\Core\FieldType\Validator[] */ - private $validators; + private array $validators; /** @var array */ private array $mimeTypes; @@ -88,13 +89,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $value->alternativeText ?? (string)$value->fileName; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Image\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -173,28 +168,28 @@ protected function checkValueStructure(BaseValue $value) /** * Validates a field based on the validators in the field definition. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\Image\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\Image\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $errors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $errors; } foreach ($this->validators as $externalValidator) { - if (!$externalValidator->validate($fieldValue, $fieldDefinition)) { + if (!$externalValidator->validate($value, $fieldDef)) { $errors = array_merge($errors, $externalValidator->getMessage()); } } - foreach ((array)$fieldDefinition->getValidatorConfiguration() as $validatorIdentifier => $parameters) { + foreach ((array)$fieldDef->getValidatorConfiguration() as $validatorIdentifier => $parameters) { switch ($validatorIdentifier) { case 'FileSizeValidator': if (empty($parameters['maxFileSize'])) { @@ -203,7 +198,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } // Database stores maxFileSize in MB - if (($parameters['maxFileSize'] * 1024 * 1024) < $fieldValue->fileSize) { + if (($parameters['maxFileSize'] * 1024 * 1024) < $value->fileSize) { $errors[] = new ValidationError( 'The file size cannot exceed %size% megabyte.', 'The file size cannot exceed %size% megabytes.', @@ -215,7 +210,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } break; case 'AlternativeTextValidator': - if ($parameters['required'] && $fieldValue->isAlternativeTextEmpty()) { + if ($parameters['required'] && $value->isAlternativeTextEmpty()) { $errors[] = new ValidationError( 'Alternative text is required.', null, @@ -230,7 +225,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) return $errors; } - public function validateFieldSettings($fieldSettings): array + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -272,7 +267,7 @@ public function validateFieldSettings($fieldSettings): array * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -333,21 +328,17 @@ public function validateValidatorConfiguration($validatorConfiguration) } /** - * {@inheritdoc} + * @param \Ibexa\Core\FieldType\Image\Value $value */ - protected function getSortInfo(BaseValue $value): bool + protected function getSortInfo(SPIValue $value): false { return false; } /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Image\Value $value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -357,13 +348,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Image\Value $value * - * @return mixed + * @return array|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -385,13 +374,9 @@ public function toHash(SPIValue $value) } /** - * Converts a $value to a persistence value. - * * @param \Ibexa\Core\FieldType\Image\Value $value - * - * @return \Ibexa\Contracts\Core\Persistence\Content\FieldValue */ - public function toPersistenceValue(SPIValue $value) + public function toPersistenceValue(SPIValue $value): FieldValue { // Store original data as external (to indicate they need to be stored) return new FieldValue( @@ -404,13 +389,9 @@ public function toPersistenceValue(SPIValue $value) } /** - * Converts a persistence $fieldValue to a Value. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\Image\Value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { if ($fieldValue->data === null) { return $this->getEmptyValue(); @@ -418,40 +399,26 @@ public function fromPersistenceValue(FieldValue $fieldValue) // Restored data comes in $data, since it has already been processed // there might be more data in the persistence value than needed here - $result = $this->fromHash( + return $this->fromHash( [ - 'id' => (isset($fieldValue->data['id']) - ? $fieldValue->data['id'] - : null), - 'alternativeText' => (isset($fieldValue->data['alternativeText']) - ? $fieldValue->data['alternativeText'] - : null), - 'fileName' => (isset($fieldValue->data['fileName']) - ? $fieldValue->data['fileName'] - : null), - 'fileSize' => (isset($fieldValue->data['fileSize']) - ? $fieldValue->data['fileSize'] - : null), - 'uri' => (isset($fieldValue->data['uri']) - ? $fieldValue->data['uri'] - : null), - 'imageId' => (isset($fieldValue->data['imageId']) - ? $fieldValue->data['imageId'] - : null), - 'width' => (isset($fieldValue->data['width']) - ? $fieldValue->data['width'] - : null), - 'height' => (isset($fieldValue->data['height']) - ? $fieldValue->data['height'] - : null), + 'id' => $fieldValue->data['id'] ?? null, + 'alternativeText' => $fieldValue->data['alternativeText'] ?? null, + 'fileName' => $fieldValue->data['fileName'] ?? null, + 'fileSize' => $fieldValue->data['fileSize'] ?? null, + 'uri' => $fieldValue->data['uri'] ?? null, + 'imageId' => $fieldValue->data['imageId'] ?? null, + 'width' => $fieldValue->data['width'] ?? null, + 'height' => $fieldValue->data['height'] ?? null, 'additionalData' => $fieldValue->data['additionalData'] ?? [], 'mime' => $fieldValue->data['mime'] ?? null, ] ); - - return $result; } + /** + * @param \Ibexa\Core\FieldType\Image\Value $value1 + * @param \Ibexa\Core\FieldType\Image\Value $value2 + */ public function valuesEqual(SPIValue $value1, SPIValue $value2): bool { $hashValue1 = $this->toHash($value1); diff --git a/src/lib/FieldType/Image/Value.php b/src/lib/FieldType/Image/Value.php index 369c8ec036..417d55ba23 100644 --- a/src/lib/FieldType/Image/Value.php +++ b/src/lib/FieldType/Image/Value.php @@ -4,39 +4,34 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Image; -use Ibexa\Contracts\Core\Repository\Exceptions\PropertyNotFoundException; +use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; use Ibexa\Core\FieldType\Value as BaseValue; class Value extends BaseValue { /** - * Image id. + * Image binary file string id. * * Required. - * - * @var mixed|null */ - public $id; + public ?string $id = null; /** - * The alternative image text (for example "Picture of an apple."). - * - * @var string|null + * The alternative image text (for example, "Picture of an apple."). */ - public $alternativeText; + public ?string $alternativeText = null; /** * Display file name of the image. * * Required. - * - * @var string|null */ - public $fileName; + public ?string $fileName = null; /** * Size of the image file. @@ -45,57 +40,63 @@ class Value extends BaseValue * * @var int|null */ - public $fileSize; + public ?int $fileSize = null; /** * The image's HTTP URI. * * @var string|null */ - public $uri; + public ?string $uri = null; /** * External image ID (required by REST for now, see https://issues.ibexa.co/browse/EZP-20831). - * - * @var mixed|null */ - public $imageId; + public ?string $imageId = null; /** * Input image file URI. - * - * @var string|null */ - public $inputUri; + public ?string $inputUri = null; /** * Original image width. - * - * @var int|null */ - public $width; + public ?int $width = null; /** * Original image height. * * @var int|null */ - public $height; + public ?int $height = null; /** @var string[] */ - public $additionalData = []; + public array $additionalData = []; public ?string $mime = null; /** - * Construct a new Value object. + * @param array{ + * id?: string|null, + * alternativeText?: string|null, + * fileName?: string|null, + * fileSize?: int|null, + * uri?: string|null, + * imageId?: string|null, + * inputUri?: string|null, + * width?: int|null, + * height?: int|null, + * additionalData?: string[], + * mime?: string|null + * } $imageData + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException if input data contains unknown property */ public function __construct(array $imageData = []) { foreach ($imageData as $key => $value) { - try { - $this->$key = $value; - } catch (PropertyNotFoundException $e) { + if (!property_exists($this, $key)) { throw new InvalidArgumentType( sprintf('Image\Value::$%s', $key), 'Existing property', @@ -103,6 +104,8 @@ public function __construct(array $imageData = []) ); } } + + parent::__construct($imageData); } public function isAlternativeTextEmpty(): bool @@ -113,7 +116,7 @@ public function isAlternativeTextEmpty(): bool /** * Creates a value only from a file path. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ public static function fromString(string $path): self { @@ -125,26 +128,29 @@ public static function fromString(string $path): self ); } - return new static( + $filesize = filesize($path); + if (false === $filesize) { + throw new InvalidArgumentException('$path', "Failed to get file size of '$path' file"); + } + + return new self( [ 'inputUri' => $path, 'fileName' => basename($path), - 'fileSize' => filesize($path), + 'fileSize' => $filesize, ] ); } /** * Returns the image file size in byte. - * - * @return int */ - public function getFileSize() + public function getFileSize(): ?int { return $this->fileSize; } - public function __toString() + public function __toString(): string { return (string)$this->fileName; } diff --git a/src/lib/FieldType/ImageAsset/Type.php b/src/lib/FieldType/ImageAsset/Type.php index 166da0292d..af747de48b 100644 --- a/src/lib/FieldType/ImageAsset/Type.php +++ b/src/lib/FieldType/ImageAsset/Type.php @@ -49,8 +49,8 @@ public function __construct( /** * Validates a field based on the validators in the field definition. * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\ImageAsset\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\ImageAsset\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] * @@ -58,16 +58,16 @@ public function __construct( * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $errors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $errors; } $content = $this->contentService->loadContent( - (int)$fieldValue->destinationContentId + (int)$value->destinationContentId ); if (!$this->assetMapper->isAsset($content)) { @@ -120,24 +120,11 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $versionInfo->names[$languageCode] ?? $versionInfo->names[$contentInfo->mainLanguageCode]; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\ImageAsset\Value - */ public function getEmptyValue(): Value { return new Value(); } - /** - * Returns if the given $value is considered empty by the field type. - * - * @param mixed $value - * - * @return bool - */ public function isEmptyValue(SPIValue $value): bool { return null === $value->destinationContentId; @@ -188,26 +175,14 @@ protected function checkValueStructure(BaseValue $value): void } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * For this FieldType, the related object's name is returned. - * - * @param \Ibexa\Core\FieldType\Relation\Value $value - * - * @return bool + * @param \Ibexa\Core\FieldType\ImageAsset\Value $value */ - protected function getSortInfo(BaseValue $value): bool + protected function getSortInfo(SPIValue $value): false { return false; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\ImageAsset\Value $value - */ - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if (!$hash) { return new Value(); @@ -222,11 +197,9 @@ public function fromHash($hash): Value } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\ImageAsset\Value $value * - * @return array + * @return array{destinationContentId: int|null, alternativeText: string|null} */ public function toHash(SPIValue $value): array { @@ -242,45 +215,18 @@ public function toHash(SPIValue $value): array } /** - * Returns relation data extracted from value. - * - * Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, - * there is an API for handling those. - * - * @param \Ibexa\Core\FieldType\ImageAsset\Value $fieldValue - * - * @return array Hash with relation type as key and array of destination content ids as value. - * - * Example: - * - * array( - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => array( - * "contentIds" => array( 12, 13, 14 ), - * "locationIds" => array( 24 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => array( - * "contentIds" => array( 12 ), - * "locationIds" => array( 24, 45 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => array( 12 ) - * ) - * + * @param \Ibexa\Core\FieldType\ImageAsset\Value $value */ - public function getRelations(SPIValue $fieldValue): array + public function getRelations(SPIValue $value): array { $relations = []; - if ($fieldValue->destinationContentId !== null) { - $relations[RelationType::ASSET->value] = [$fieldValue->destinationContentId]; + if ($value->destinationContentId !== null) { + $relations[RelationType::ASSET->value] = [$value->destinationContentId]; } return $relations; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/ImageAsset/Value.php b/src/lib/FieldType/ImageAsset/Value.php index e1510d10fa..092b128e4c 100644 --- a/src/lib/FieldType/ImageAsset/Value.php +++ b/src/lib/FieldType/ImageAsset/Value.php @@ -13,35 +13,17 @@ class Value extends BaseValue { /** - * Related content id's. - * - * @var mixed|null + * @param int|null $destinationContentId Related content's ID. + * @param string|null $alternativeText The alternative image text (for example, "Picture of an apple."). */ - public $destinationContentId; - - /** - * The alternative image text (for example "Picture of an apple."). - * - * @var string|null - */ - public $alternativeText; - - /** - * @param mixed|null $destinationContentId - * @param string|null $alternativeText - */ - public function __construct($destinationContentId = null, ?string $alternativeText = null) - { - parent::__construct([ - 'destinationContentId' => $destinationContentId, - 'alternativeText' => $alternativeText, - ]); + public function __construct( + public readonly ?int $destinationContentId = null, + public readonly ?string $alternativeText = null + ) { + parent::__construct(); } - /** - * {@inheritdoc} - */ - public function __toString() + public function __toString(): string { return (string) $this->destinationContentId; } diff --git a/src/lib/FieldType/Integer/Type.php b/src/lib/FieldType/Integer/Type.php index a72e4e8067..8ca8e4d313 100644 --- a/src/lib/FieldType/Integer/Type.php +++ b/src/lib/FieldType/Integer/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Integer; @@ -23,7 +24,7 @@ */ class Type extends BaseNumericType implements TranslationContainerInterface { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'IntegerValueValidator' => [ 'minIntegerValue' => [ 'type' => 'int', @@ -59,18 +60,12 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - */ public function getEmptyValue(): Value { return new Value(); } /** - * Returns if the given $value is considered empty by the field type. - * * @param \Ibexa\Core\FieldType\Integer\Value $value */ public function isEmptyValue(SPIValue $value): bool @@ -115,19 +110,12 @@ protected function checkValueStructure(BaseValue $value): void /** * @param \Ibexa\Core\FieldType\Integer\Value $value */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): ?int { return $value->value; } - /** - * Converts a $hash to the Value defined by the field type. - * - * @param int|string|null $hash - * - * @return \Ibexa\Core\FieldType\Integer\Value $value - */ - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -137,8 +125,6 @@ public function fromHash($hash): Value } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Integer\Value $value */ public function toHash(SPIValue $value): ?int @@ -150,11 +136,6 @@ public function toHash(SPIValue $value): ?int return $value->value; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/Integer/Value.php b/src/lib/FieldType/Integer/Value.php index 0e533e9597..d66a8c7350 100644 --- a/src/lib/FieldType/Integer/Value.php +++ b/src/lib/FieldType/Integer/Value.php @@ -4,34 +4,23 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Integer; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Integer field type. + * Value for the Integer field type. */ class Value extends BaseValue { - /** - * Content of the value. - * - * @var int|null - */ - public $value; - - /** - * Construct a new Value object and initialize with $value. - * - * @param int|null $value - */ - public function __construct($value = null) + public function __construct(public readonly ?int $value = null) { - $this->value = $value; + parent::__construct(); } - public function __toString() + public function __toString(): string { return (string)$this->value; } diff --git a/src/lib/FieldType/Keyword/Type.php b/src/lib/FieldType/Keyword/Type.php index fc740e4e32..27299f7d40 100644 --- a/src/lib/FieldType/Keyword/Type.php +++ b/src/lib/FieldType/Keyword/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Keyword; @@ -44,13 +45,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return implode(', ', $value->values); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Keyword\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value([]); } @@ -104,13 +99,13 @@ protected function checkValueStructure(BaseValue $value) } /** - * @param \Ibexa\Core\FieldType\Keyword\Value $fieldValue + * @param \Ibexa\Core\FieldType\Keyword\Value $value */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - foreach ($fieldValue->values as $keyword) { + foreach ($value->values as $keyword) { if (!is_string($keyword)) { $validationErrors[] = new ValidationError( 'Each keyword must be a string.', @@ -132,55 +127,37 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } /** - * {@inheritdoc} + * @param \Ibexa\Core\FieldType\Keyword\Value $value */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { return implode(',', $value->values); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Keyword\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value($hash); } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Keyword\Value $value * - * @return mixed + * @return string[] */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): array { return $value->values; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } /** - * Converts a $value to a persistence value. - * * @param \Ibexa\Core\FieldType\Keyword\Value $value - * - * @return \Ibexa\Contracts\Core\Persistence\Content\FieldValue */ - public function toPersistenceValue(SPIValue $value) + public function toPersistenceValue(SPIValue $value): FieldValue { return new FieldValue( [ @@ -191,14 +168,7 @@ public function toPersistenceValue(SPIValue $value) ); } - /** - * Converts a persistence $fieldValue to a Value. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\Keyword\Value - */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { return new Value($fieldValue->externalData); } diff --git a/src/lib/FieldType/Keyword/Value.php b/src/lib/FieldType/Keyword/Value.php index 9dc2aa2103..50728fac89 100644 --- a/src/lib/FieldType/Keyword/Value.php +++ b/src/lib/FieldType/Keyword/Value.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Keyword; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Keyword field type. + * Value for the Keyword field type. */ class Value extends BaseValue { @@ -19,21 +20,21 @@ class Value extends BaseValue * * @var string[] */ - public $values = []; + public readonly array $values; /** * Construct a new Value object and initialize with $values. * - * @param string[]|string $values + * @param string[]|string $values either an array of keywords or a comma-separated list of keywords */ - public function __construct($values = null) + public function __construct(array|string|null $values = null) { if ($values !== null) { if (!is_array($values)) { $tags = []; foreach (explode(',', $values) as $tag) { $tag = trim($tag); - if ($tag) { + if (!empty($tag)) { $tags[] = $tag; } } @@ -41,7 +42,11 @@ public function __construct($values = null) } $this->values = array_unique($values); + } else { + $this->values = []; } + + parent::__construct(); } /** @@ -49,7 +54,7 @@ public function __construct($values = null) * * @return string A comma separated list of tags, eg: "php, Ibexa, html5" */ - public function __toString() + public function __toString(): string { return implode(', ', $this->values); } diff --git a/src/lib/FieldType/MapLocation/Type.php b/src/lib/FieldType/MapLocation/Type.php index dd5e13d414..93cce30494 100644 --- a/src/lib/FieldType/MapLocation/Type.php +++ b/src/lib/FieldType/MapLocation/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\MapLocation; @@ -41,23 +42,13 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value->address; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\MapLocation\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } /** - * Returns if the given $value is considered empty by the field type. - * - * @param mixed $value - * - * @return bool + * @param \Ibexa\Core\FieldType\MapLocation\Value $value */ public function isEmptyValue(SPIValue $value): bool { @@ -116,22 +107,13 @@ protected function checkValueStructure(BaseValue $value) * Returns information for FieldValue->$sortKey relevant to the field type. * * @param \Ibexa\Core\FieldType\MapLocation\Value $value - * - * @return string */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): string { return $this->transformationProcessor->transformByGroup((string)$value, 'lowercase'); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\MapLocation\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -141,13 +123,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\MapLocation\Value $value * - * @return mixed + * @return array{latitude: float|null, longitude: float|null, address: string|null}|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -160,24 +140,15 @@ public function toHash(SPIValue $value) ]; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } /** - * Converts a $value to a persistence value. - * * @param \Ibexa\Core\FieldType\MapLocation\Value $value - * - * @return \Ibexa\Contracts\Core\Persistence\Content\FieldValue */ - public function toPersistenceValue(SPIValue $value) + public function toPersistenceValue(SPIValue $value): FieldValue { return new FieldValue( [ @@ -188,14 +159,7 @@ public function toPersistenceValue(SPIValue $value) ); } - /** - * Converts a persistence $fieldValue to a Value. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\MapLocation\Value - */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { if ($fieldValue->externalData === null) { return $this->getEmptyValue(); diff --git a/src/lib/FieldType/MapLocation/Value.php b/src/lib/FieldType/MapLocation/Value.php index 5118103b49..47af731ca9 100644 --- a/src/lib/FieldType/MapLocation/Value.php +++ b/src/lib/FieldType/MapLocation/Value.php @@ -4,60 +4,52 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\MapLocation; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for MapLocation field type. + * Value for the MapLocation field type. */ class Value extends BaseValue { /** * Latitude of the location. - * - * @var float|null */ - public $latitude; + public readonly ?float $latitude; /** * Longitude of the location. - * - * @var float|null */ - public $longitude; + public readonly ?float $longitude; /** * Display address for the location. - * - * @var string|null */ - public $address; + public readonly ?string $address; /** - * Construct a new Value object and initialize with $values. - * - * @param string[]|string $values + * @param array{latitude: float|null, longitude: float|null, address: string|string[]|null}|null $values */ - public function __construct(array $values = null) + public function __construct(?array $values = null) { - foreach ((array)$values as $key => $value) { - $this->$key = $value; + if (null !== $values) { + $this->latitude = $values['latitude'] ?? null; + $this->longitude = $values['longitude'] ?? null; + + $address = is_array($values['address'] ?? null) + ? implode(', ', $values['address']) + : ($values['address'] ?? null); + $this->address = $address; } + + parent::__construct(); } - /** - * Returns a string representation of the keyword value. - * - * @return string A comma separated list of tags, eg: "php, Ibexa, html5" - */ - public function __toString() + public function __toString(): string { - if (is_array($this->address)) { - return implode(', ', $this->address); - } - return (string)$this->address; } } diff --git a/src/lib/FieldType/Media/Type.php b/src/lib/FieldType/Media/Type.php index 47b4de0bed..71433c1809 100644 --- a/src/lib/FieldType/Media/Type.php +++ b/src/lib/FieldType/Media/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Media; @@ -26,18 +27,18 @@ class Type extends BaseType implements TranslationContainerInterface /** * List of possible media type settings. */ - public const TYPE_FLASH = 'flash'; - public const TYPE_QUICKTIME = 'quick_time'; - public const TYPE_REALPLAYER = 'real_player'; - public const TYPE_SILVERLIGHT = 'silverlight'; - public const TYPE_WINDOWSMEDIA = 'windows_media_player'; - public const TYPE_HTML5_VIDEO = 'html5_video'; - public const TYPE_HTML5_AUDIO = 'html5_audio'; + public const string TYPE_FLASH = 'flash'; + public const string TYPE_QUICKTIME = 'quick_time'; + public const string TYPE_REALPLAYER = 'real_player'; + public const string TYPE_SILVERLIGHT = 'silverlight'; + public const string TYPE_WINDOWSMEDIA = 'windows_media_player'; + public const string TYPE_HTML5_VIDEO = 'html5_video'; + public const string TYPE_HTML5_AUDIO = 'html5_audio'; /** * Type constants for validation. */ - private static $availableTypes = [ + private static array $availableTypes = [ self::TYPE_FLASH, self::TYPE_QUICKTIME, self::TYPE_REALPLAYER, @@ -48,7 +49,7 @@ class Type extends BaseType implements TranslationContainerInterface ]; /** @var array */ - protected $settingsSchema = [ + protected array $settingsSchema = [ 'mediaType' => [ 'type' => 'choice', 'default' => self::TYPE_HTML5_VIDEO, @@ -65,43 +66,26 @@ public function getFieldTypeIdentifier(): string return 'ibexa_media'; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Media\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; foreach ($fieldSettings as $name => $value) { if (isset($this->settingsSchema[$name])) { - switch ($name) { - case 'mediaType': - if (!in_array($value, self::$availableTypes)) { - $validationErrors[] = new ValidationError( - "Setting '%setting%' is of unknown type", - null, - [ - '%setting%' => $name, - ], - "[$name]" - ); - } - break; + if ($name === 'mediaType' && !in_array($value, self::$availableTypes, true)) { + $validationErrors[] = new ValidationError( + "Setting '%setting%' is of unknown type", + null, + [ + '%setting%' => $name, + ], + "[$name]" + ); } } else { $validationErrors[] = new ValidationError( @@ -209,13 +193,11 @@ protected function completeValue(BaseValue $value) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Media\Value $value * - * @return mixed + * @return array|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -232,21 +214,13 @@ public function toHash(SPIValue $value) return $hash; } - /** - * Converts a persistence $fieldValue to a Value. - * - * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\Media\Value - */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { if ($fieldValue->externalData === null) { return $this->getEmptyValue(); } + /** @var \Ibexa\Core\FieldType\Media\Value $result */ $result = parent::fromPersistenceValue($fieldValue); $result->hasController = $fieldValue->externalData['hasController'] ?? false; @@ -258,11 +232,6 @@ public function fromPersistenceValue(FieldValue $fieldValue) return $result; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return false; diff --git a/src/lib/FieldType/Media/Value.php b/src/lib/FieldType/Media/Value.php index e14ecf335b..b94dafc431 100644 --- a/src/lib/FieldType/Media/Value.php +++ b/src/lib/FieldType/Media/Value.php @@ -4,48 +4,39 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Media; use Ibexa\Core\FieldType\BinaryBase\Value as BaseValue; /** - * Value for Media field type. + * Value for the Media field type. */ class Value extends BaseValue { /** * If the media has a controller when being displayed. - * - * @var bool */ - public $hasController = false; + public bool $hasController = false; /** * If the media should be automatically played. - * - * @var bool */ - public $autoplay = false; + public bool $autoplay = false; /** * If the media should be played in a loop. - * - * @var bool */ - public $loop = false; + public bool $loop = false; /** * Height of the media. - * - * @var int */ - public $height = 0; + public int $height = 0; /** * Width of the media. - * - * @var int */ - public $width = 0; + public int $width = 0; } diff --git a/src/lib/FieldType/Null/Type.php b/src/lib/FieldType/Null/Type.php index 6f103b17da..c49b414b4b 100644 --- a/src/lib/FieldType/Null/Type.php +++ b/src/lib/FieldType/Null/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Null; @@ -18,45 +19,29 @@ class Type extends FieldType { /** - * Identifier for the field type this stuff is mocking. - * - * @var string - */ - protected $fieldTypeIdentifier; - - /** - * @param string $fieldTypeIdentifier + * @param string $fieldTypeIdentifier Identifier for the field type that is being mocked. */ - public function __construct($fieldTypeIdentifier) + public function __construct(protected readonly string $fieldTypeIdentifier) { - $this->fieldTypeIdentifier = $fieldTypeIdentifier; } /** * Returns the field type identifier for this field type. - * - * @return string */ - public function getFieldTypeIdentifier() + public function getFieldTypeIdentifier(): string { return $this->fieldTypeIdentifier; } /** - * @param \Ibexa\Core\FieldType\Null\Value|\Ibexa\Contracts\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\Null\Value $value */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { return (string)$value->value; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Null\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(null); } @@ -68,7 +53,7 @@ public function getEmptyValue() * * @return \Ibexa\Core\FieldType\Null\Value The potentially converted and structurally plausible value. */ - protected function createValueFromInput($inputValue) + protected function createValueFromInput($inputValue): Value { return $inputValue; } @@ -85,47 +70,19 @@ protected function checkValueStructure(BaseValue $value) // Does nothing } - /** - * {@inheritdoc} - */ - protected function getSortInfo(BaseValue $value) - { - return null; - } - - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Null\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value($hash); } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Null\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): null { - if (isset($value->value)) { - return $value->value; - } - return null; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/Null/Value.php b/src/lib/FieldType/Null/Value.php index a55d5e16dc..b9cebcd093 100644 --- a/src/lib/FieldType/Null/Value.php +++ b/src/lib/FieldType/Null/Value.php @@ -4,35 +4,24 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Null; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Null field type. + * Value for the Null field type. */ class Value extends BaseValue { - /** - * Content of the value. - * - * @var mixed - */ - public $value = null; - - /** - * Construct a new Value object and initialize with $value. - * - * @param int $value - */ - public function __construct($value = null) + public function __construct(public readonly null $value = null) { - $this->value = $value; + parent::__construct(); } - public function __toString() + public function __toString(): string { - return (string)$this->value; + return 'null'; } } diff --git a/src/lib/FieldType/Relation/Type.php b/src/lib/FieldType/Relation/Type.php index 84f969313b..4d0303a2d2 100644 --- a/src/lib/FieldType/Relation/Type.php +++ b/src/lib/FieldType/Relation/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Relation; @@ -35,7 +36,7 @@ class Type extends FieldType implements TranslationContainerInterface public const SELECTION_BROWSE = 0; public const SELECTION_DROPDOWN = 1; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'selectionMethod' => [ 'type' => 'int', 'default' => self::SELECTION_BROWSE, @@ -68,7 +69,7 @@ public function __construct( $this->targetContentValidator = $targetContentValidator; } - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -180,41 +181,31 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin * * @return \Ibexa\Core\FieldType\ValidationError[] */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $allowedContentTypes = $fieldDefinition->getFieldSettings()['selectionContentTypes'] ?? []; + $allowedContentTypes = $fieldDef->getFieldSettings()['selectionContentTypes'] ?? []; $validationError = $this->targetContentValidator->validate( - (int) $fieldValue->destinationContentId, + (int) $value->destinationContentId, $allowedContentTypes ); return $validationError === null ? $validationErrors : [$validationError]; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Relation\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } /** - * Returns if the given $value is considered empty by the field type. - * - * @param mixed $value - * - * @return bool + * @param \Ibexa\Core\FieldType\Relation\Value $value */ public function isEmptyValue(SPIValue $value): bool { @@ -259,26 +250,16 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * For this FieldType, the related object's name is returned. + * For this FieldType, the related content item ID is returned as a string. * * @param \Ibexa\Core\FieldType\Relation\Value $value - * - * @return string */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { return (string)$value; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Relation\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash !== null) { $destinationContentId = $hash['destinationContentId']; @@ -295,60 +276,28 @@ public function fromHash($hash) * * @param \Ibexa\Core\FieldType\Relation\Value $value * - * @return mixed + * @return array{destinationContentId: int|null} */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): array { - $destinationContentId = null; - if ($value->destinationContentId !== null) { - $destinationContentId = (int)$value->destinationContentId; - } - return [ - 'destinationContentId' => $destinationContentId, + 'destinationContentId' => $value->destinationContentId ?? null, ]; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } /** - * Returns relation data extracted from value. - * - * Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, - * there is an API for handling those. - * - * @param \Ibexa\Core\FieldType\Relation\Value $fieldValue - * - * @return array Hash with relation type as key and array of destination content ids as value. - * - * Example: - * - * array( - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => array( - * "contentIds" => array( 12, 13, 14 ), - * "locationIds" => array( 24 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => array( - * "contentIds" => array( 12 ), - * "locationIds" => array( 24, 45 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => array( 12 ) - * ) - * + * @param \Ibexa\Core\FieldType\Relation\Value $value */ - public function getRelations(SPIValue $fieldValue) + public function getRelations(SPIValue $value): array { $relations = []; - if ($fieldValue->destinationContentId !== null) { - $relations[RelationType::FIELD->value] = [$fieldValue->destinationContentId]; + if ($value->destinationContentId !== null) { + $relations[RelationType::FIELD->value] = [$value->destinationContentId]; } return $relations; diff --git a/src/lib/FieldType/Relation/Value.php b/src/lib/FieldType/Relation/Value.php index 1ad3a7f949..378da3e9f6 100644 --- a/src/lib/FieldType/Relation/Value.php +++ b/src/lib/FieldType/Relation/Value.php @@ -4,37 +4,31 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Relation; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Relation field type. + * Value for the Relation field type. */ class Value extends BaseValue { - /** - * Related content. - * - * @var mixed|null - */ - public $destinationContentId; - /** * Construct a new Value object and initialize it $destinationContent. * - * @param mixed $destinationContentId Content id the relation is to + * @param int|null $destinationContentId Content id the relation is to */ - public function __construct($destinationContentId = null) + public function __construct(public readonly ?int $destinationContentId = null) { - $this->destinationContentId = $destinationContentId; + parent::__construct(); } /** - * Returns the related content's name. + * Returns the related content item ID as a string. */ - public function __toString() + public function __toString(): string { return (string)$this->destinationContentId; } diff --git a/src/lib/FieldType/RelationList/Type.php b/src/lib/FieldType/RelationList/Type.php index 62119496e4..3a97ef43eb 100644 --- a/src/lib/FieldType/RelationList/Type.php +++ b/src/lib/FieldType/RelationList/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\RelationList; @@ -44,7 +45,7 @@ class Type extends FieldType implements TranslationContainerInterface public const SELECTION_TEMPLATE_BASED_MULTIPLE = 5; public const SELECTION_TEMPLATE_BASED_SINGLE = 6; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'selectionMethod' => [ 'type' => 'int', 'default' => self::SELECTION_BROWSE, @@ -63,7 +64,7 @@ class Type extends FieldType implements TranslationContainerInterface ], ]; - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'RelationListValueValidator' => [ 'selectionLimit' => [ 'type' => 'int', @@ -86,7 +87,7 @@ public function __construct( $this->targetContentValidator = $targetContentValidator; } - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -194,7 +195,7 @@ public function validateFieldSettings($fieldSettings) * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -255,21 +256,21 @@ public function validateValidatorConfiguration($validatorConfiguration) * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $validatorConfiguration = $fieldDefinition->getValidatorConfiguration(); + $validatorConfiguration = $fieldDef->getValidatorConfiguration(); $constraints = $validatorConfiguration['RelationListValueValidator'] ?? []; $validationErrors = []; if (isset($constraints['selectionLimit']) && - $constraints['selectionLimit'] > 0 && count($fieldValue->destinationContentIds) > $constraints['selectionLimit']) { + $constraints['selectionLimit'] > 0 && count($value->destinationContentIds) > $constraints['selectionLimit']) { $validationErrors[] = new ValidationError( 'The selected content items number cannot be higher than %limit%.', null, @@ -280,9 +281,9 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - $allowedContentTypes = $fieldDefinition->getFieldSettings()['selectionContentTypes'] ?? []; + $allowedContentTypes = $fieldDef->getFieldSettings()['selectionContentTypes'] ?? []; - foreach ($fieldValue->destinationContentIds as $destinationContentId) { + foreach ($value->destinationContentIds as $destinationContentId) { $validationError = $this->targetContentValidator->validate((int) $destinationContentId, $allowedContentTypes); if ($validationError !== null) { $validationErrors[] = $validationError; @@ -330,13 +331,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return implode(' ', $names); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\RelationList\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -393,81 +388,40 @@ protected function checkValueStructure(BaseValue $value) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * For this FieldType, the related objects IDs are returned, separated by ",". * * @param \Ibexa\Core\FieldType\RelationList\Value $value - * - * @return string */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { return implode(',', $value->destinationContentIds); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\RelationList\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value($hash['destinationContentIds']); } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\RelationList\Value $value * - * @return mixed + * @return array{destinationContentIds: int[]} */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): array { return ['destinationContentIds' => $value->destinationContentIds]; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } /** - * Returns relation data extracted from value. - * - * Not intended for \Ibexa\Contracts\Core\Repository\Values\Content\Relation::COMMON type relations, - * there is an API for handling those. - * * @param \Ibexa\Core\FieldType\RelationList\Value $value - * - * @return array Hash with relation type as key and array of destination content ids as value. - * - * Example: - * - * array( - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::LINK => array( - * "contentIds" => array( 12, 13, 14 ), - * "locationIds" => array( 24 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::EMBED => array( - * "contentIds" => array( 12 ), - * "locationIds" => array( 24, 45 ) - * ), - * \Ibexa\Contracts\Core\Repository\Values\Content\Relation::FIELD => array( 12 ) - * ) - * */ - public function getRelations(SPIValue $value) + public function getRelations(SPIValue $value): array { - /* @var \Ibexa\Core\FieldType\RelationList\Value $value */ return [ RelationType::FIELD->value => $value->destinationContentIds, ]; diff --git a/src/lib/FieldType/RelationList/Value.php b/src/lib/FieldType/RelationList/Value.php index d4f9f11524..c8823b617f 100644 --- a/src/lib/FieldType/RelationList/Value.php +++ b/src/lib/FieldType/RelationList/Value.php @@ -4,34 +4,26 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\RelationList; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for RelationList field type. + * Value for the RelationList field type. */ class Value extends BaseValue { /** - * Related content id's. - * - * @var mixed[] + * @param int[] $destinationContentIds */ - public $destinationContentIds; - - /** - * Construct a new Value object and initialize it $text. - * - * @param mixed[] $destinationContentIds - */ - public function __construct(array $destinationContentIds = []) + public function __construct(public readonly array $destinationContentIds = []) { - $this->destinationContentIds = $destinationContentIds; + parent::__construct(); } - public function __toString() + public function __toString(): string { return implode(',', $this->destinationContentIds); } diff --git a/src/lib/FieldType/Selection/Type.php b/src/lib/FieldType/Selection/Type.php index 60e323d738..a811df9afb 100644 --- a/src/lib/FieldType/Selection/Type.php +++ b/src/lib/FieldType/Selection/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Selection; @@ -31,7 +32,7 @@ class Type extends FieldType implements TranslationContainerInterface * * @var mixed */ - protected $settingsSchema = [ + protected array $settingsSchema = [ 'isMultiple' => [ 'type' => 'bool', 'default' => false, @@ -46,14 +47,7 @@ class Type extends FieldType implements TranslationContainerInterface ], ]; - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; @@ -151,13 +145,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return implode(' ', $names); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Selection\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -201,25 +189,25 @@ protected function checkValueStructure(BaseValue $value) * * Does not use validators. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\Selection\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\Selection\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $fieldSettings = $fieldDefinition->getFieldSettings(); + $fieldSettings = $fieldDef->getFieldSettings(); if ((!isset($fieldSettings['isMultiple']) || $fieldSettings['isMultiple'] === false) - && count($fieldValue->selection) > 1) { + && count($value->selection) > 1) { $validationErrors[] = new ValidationError( 'Field definition does not allow multiple options to be selected.', null, @@ -228,7 +216,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - foreach ($fieldValue->selection as $optionIndex) { + foreach ($value->selection as $optionIndex) { if (!isset($fieldSettings['options'][$optionIndex]) && empty($fieldSettings['multilingualOptions'])) { $validationErrors[] = new ValidationError( 'Option with index %index% does not exist in the field definition.', @@ -249,7 +237,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) $possibleOptionIndexes = array_merge(...array_values($possibleOptionIndexesByLanguage)); - foreach ($fieldValue->selection as $optionIndex) { + foreach ($value->selection as $optionIndex) { if (!in_array($optionIndex, $possibleOptionIndexes)) { $validationErrors[] = new ValidationError( 'Option with index %index% does not exist in the field definition.', @@ -267,46 +255,28 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\Selection\Value $value - * - * @return string */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { return implode('-', $value->selection); } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Selection\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { return new Value($hash); } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Selection\Value $value * - * @return mixed + * @return int[] */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): array { return $value->selection; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; diff --git a/src/lib/FieldType/Selection/Value.php b/src/lib/FieldType/Selection/Value.php index e3dd36b5f5..1b098cb8f2 100644 --- a/src/lib/FieldType/Selection/Value.php +++ b/src/lib/FieldType/Selection/Value.php @@ -4,34 +4,26 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Selection; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Selection field type. + * Value for a Selection field type. */ class Value extends BaseValue { /** - * Selection content. - * - * @var int[] - */ - public $selection; - - /** - * Construct a new Value object and initialize it $selection. - * * @param int[] $selection */ - public function __construct(array $selection = []) + public function __construct(public readonly array $selection = []) { - $this->selection = $selection; + parent::__construct(); } - public function __toString() + public function __toString(): string { return implode(',', $this->selection); } diff --git a/src/lib/FieldType/TextBlock/Type.php b/src/lib/FieldType/TextBlock/Type.php index 245decbc26..f002d49744 100644 --- a/src/lib/FieldType/TextBlock/Type.php +++ b/src/lib/FieldType/TextBlock/Type.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\TextBlock; +use Ibexa\Contracts\Core\FieldType\Value as SPIValue; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; use Ibexa\Core\FieldType\BaseTextType; use Ibexa\Core\FieldType\ValidationError; -use Ibexa\Core\FieldType\Value as BaseValue; use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Translation\TranslationContainerInterface; @@ -21,14 +22,14 @@ */ class Type extends BaseTextType implements TranslationContainerInterface { - protected $settingsSchema = [ + protected array $settingsSchema = [ 'textRows' => [ 'type' => 'int', 'default' => 10, ], ]; - protected $validatorConfigurationSchema = []; + protected array $validatorConfigurationSchema = []; public function getFieldTypeIdentifier(): string { @@ -62,13 +63,9 @@ protected static function checkValueType(mixed $value): void } /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * * @param \Ibexa\Core\FieldType\TextBlock\Value $value - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { $tokens = strtok(trim($value->text), "\r\n"); @@ -77,10 +74,7 @@ protected function getSortInfo(BaseValue $value): string : ''; } - /** - * @param string $hash - */ - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -89,14 +83,7 @@ public function fromHash($hash): Value return new Value($hash); } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings): array + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/TextBlock/Value.php b/src/lib/FieldType/TextBlock/Value.php index bc8d61e013..1431ee106a 100644 --- a/src/lib/FieldType/TextBlock/Value.php +++ b/src/lib/FieldType/TextBlock/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\TextBlock; diff --git a/src/lib/FieldType/TextLine/Type.php b/src/lib/FieldType/TextLine/Type.php index eb502ee0d4..8cf6b6ce0b 100644 --- a/src/lib/FieldType/TextLine/Type.php +++ b/src/lib/FieldType/TextLine/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\TextLine; @@ -12,7 +13,6 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\BaseTextType; use Ibexa\Core\FieldType\Validator\StringLengthValidator; -use Ibexa\Core\FieldType\Value as BaseValue; use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Translation\TranslationContainerInterface; @@ -23,7 +23,7 @@ */ class Type extends BaseTextType implements TranslationContainerInterface { - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'StringLengthValidator' => [ 'minStringLength' => [ 'type' => 'int', @@ -39,11 +39,11 @@ class Type extends BaseTextType implements TranslationContainerInterface /** * Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. * - * @param array $validatorConfiguration + * @param mixed $validatorConfiguration * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] */ - public function validateValidatorConfiguration($validatorConfiguration): array + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; $validators = ['StringLengthValidator' => new StringLengthValidator()]; @@ -62,27 +62,27 @@ public function validateValidatorConfiguration($validatorConfiguration): array /** * Validates a field based on the validators in the field definition. * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\TextLine\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\TextLine\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\PropertyNotFoundException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue): array + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $validationErrors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $validationErrors; } - $validatorConfiguration = $fieldDefinition->getValidatorConfiguration(); + $validatorConfiguration = $fieldDef->getValidatorConfiguration(); $constraints = $validatorConfiguration['StringLengthValidator'] ?? []; $validator = new StringLengthValidator(); $validator->initializeWithConstraints($constraints); - return false === $validator->validate($fieldValue, $fieldDefinition) ? $validator->getMessage() : []; + return false === $validator->validate($value, $fieldDef) ? $validator->getMessage() : []; } public function getFieldTypeIdentifier(): string @@ -90,9 +90,6 @@ public function getFieldTypeIdentifier(): string return 'ibexa_string'; } - /** - * @return \Ibexa\Core\FieldType\TextLine\Value - */ public function getEmptyValue(): Value { return new Value(); @@ -124,15 +121,12 @@ protected static function checkValueType(mixed $value): void * * @param \Ibexa\Core\FieldType\TextLine\Value $value */ - protected function getSortInfo(BaseValue $value): string + protected function getSortInfo(SPIValue $value): string { return $this->transformationProcessor->transformByGroup((string)$value, 'lowercase'); } - /** - * @param string $hash - */ - public function fromHash($hash): Value + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); diff --git a/src/lib/FieldType/TextLine/Value.php b/src/lib/FieldType/TextLine/Value.php index 7e135878d5..d7c58c8317 100644 --- a/src/lib/FieldType/TextLine/Value.php +++ b/src/lib/FieldType/TextLine/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\TextLine; @@ -14,19 +15,12 @@ */ class Value extends BaseValue { - /** - * Text content. - */ - public string $text; - - public function __construct(?string $text = '') + public function __construct(public readonly string $text = '') { parent::__construct(); - - $this->text = (string)$text; } - public function __toString() + public function __toString(): string { return $this->text; } diff --git a/src/lib/FieldType/Time/Type.php b/src/lib/FieldType/Time/Type.php index 5e3bd604eb..5fa44ce9c3 100644 --- a/src/lib/FieldType/Time/Type.php +++ b/src/lib/FieldType/Time/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Time; @@ -29,7 +30,7 @@ class Type extends FieldType implements TranslationContainerInterface */ public const DEFAULT_CURRENT_TIME = 1; - protected $settingsSchema = [ + protected array $settingsSchema = [ 'useSeconds' => [ 'type' => 'bool', 'default' => false, @@ -67,13 +68,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return $dateTime->format('g:i:s a'); } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Time\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -124,22 +119,13 @@ protected function checkValueStructure(BaseValue $value) * Returns information for FieldValue->$sortKey relevant to the field type. * * @param \Ibexa\Core\FieldType\Time\Value $value - * - * @return int */ - protected function getSortInfo(BaseValue $value) + protected function getSortInfo(SPIValue $value): ?int { return $value->time; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param int $hash Number of seconds since Unix Epoch - * - * @return \Ibexa\Core\FieldType\Time\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -149,30 +135,17 @@ public function fromHash($hash) } /** - * Returns if the given $value is considered empty by the field type. - * - * - * @param \Ibexa\Core\FieldType\Value $value - * - * @return bool + * @param \Ibexa\Core\FieldType\Time\Value $value */ public function isEmptyValue(SPIValue $value): bool { - if ($value->time === null) { - return true; - } - - return false; + return $value->time === null; } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Time\Value $value - * - * @return mixed */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?int { if ($this->isEmptyValue($value)) { return null; @@ -181,24 +154,12 @@ public function toHash(SPIValue $value) return $value->time; } - /** - * Returns whether the field type is searchable. - * - * @return bool - */ public function isSearchable(): bool { return true; } - /** - * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. - * - * @param mixed $fieldSettings - * - * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/Time/Value.php b/src/lib/FieldType/Time/Value.php index 29e9057464..6a8d27e36b 100644 --- a/src/lib/FieldType/Time/Value.php +++ b/src/lib/FieldType/Time/Value.php @@ -4,67 +4,57 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Time; use DateTime; +use DateTimeInterface; use Exception; use Ibexa\Core\Base\Exceptions\InvalidArgumentValue; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Time field type. + * Value for the Time field type. */ class Value extends BaseValue { /** * Time of day as number of seconds. - * - * @var int|null */ - public $time; + public readonly ?int $time; /** * Time format to be used by {@link __toString()}. - * - * @var string */ - public $stringFormat = 'H:i:s'; + public string $stringFormat = 'H:i:s'; /** - * Construct a new Value object and initialize it with $seconds as number of seconds from beginning of day. - * - * @param mixed $seconds + * Construct a new Value object and initialize it with $seconds as number of seconds from the beginning of a day. */ - public function __construct($seconds = null) + public function __construct(?int $seconds = null) { $this->time = $seconds; + + parent::__construct(); } /** * Creates a Value from the given $dateTime. - * - * @param \DateTime $dateTime - * - * @return \Ibexa\Core\FieldType\Time\Value */ - public static function fromDateTime(DateTime $dateTime) + public static function fromDateTime(DateTimeInterface $dateTime): Value { $dateTime = clone $dateTime; - return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp()); + return new self($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp()); } /** * Creates a Value from the given $timeString. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param string $timeString - * - * @return \Ibexa\Core\FieldType\Time\Value */ - public static function fromString($timeString) + public static function fromString(string $timeString): Value { try { return static::fromDateTime(new DateTime($timeString)); @@ -77,12 +67,8 @@ public static function fromString($timeString) * Creates a Value from the given $timestamp. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param int $timestamp - * - * @return static */ - public static function fromTimestamp($timestamp) + public static function fromTimestamp(int $timestamp): Value { try { $dateTime = new DateTime("@{$timestamp}"); @@ -93,14 +79,12 @@ public static function fromTimestamp($timestamp) } } - public function __toString() + public function __toString(): string { if ($this->time === null) { return ''; } - $dateTime = new DateTime("@{$this->time}"); - - return $dateTime->format($this->stringFormat); + return (new DateTime("@{$this->time}"))->format($this->stringFormat); } } diff --git a/src/lib/FieldType/Url/Type.php b/src/lib/FieldType/Url/Type.php index 0fc80fca91..1cd10bf47e 100644 --- a/src/lib/FieldType/Url/Type.php +++ b/src/lib/FieldType/Url/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Url; @@ -41,13 +42,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value->text; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\Url\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -94,22 +89,12 @@ protected function checkValueStructure(BaseValue $value) } } - /** - * {@inheritdoc} - */ - protected function getSortInfo(BaseValue $value): bool + protected function getSortInfo(SPIValue $value): false { return false; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\Url\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -123,13 +108,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\Url\Value $value * - * @return mixed + * @return array{link: string|null, text: string|null}|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -138,18 +121,11 @@ public function toHash(SPIValue $value) return ['link' => $value->link, 'text' => $value->text]; } - public function toPersistenceValue(SPIValue $value) + /** + * @param \Ibexa\Core\FieldType\Url\Value $value + */ + public function toPersistenceValue(SPIValue $value): FieldValue { - if ($value === null) { - return new FieldValue( - [ - 'data' => [], - 'externalData' => null, - 'sortKey' => null, - ] - ); - } - return new FieldValue( [ 'data' => [ @@ -162,16 +138,7 @@ public function toPersistenceValue(SPIValue $value) ); } - /** - * Converts a persistence $fieldValue to a Value. - * - * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\Url\Value - */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { if ($fieldValue->externalData === null) { return $this->getEmptyValue(); @@ -179,7 +146,7 @@ public function fromPersistenceValue(FieldValue $fieldValue) return new Value( $fieldValue->externalData, - $fieldValue->data['text'] + $fieldValue->data['text'] ?? null ); } diff --git a/src/lib/FieldType/Url/Value.php b/src/lib/FieldType/Url/Value.php index ae76e5a900..68c8c439b7 100644 --- a/src/lib/FieldType/Url/Value.php +++ b/src/lib/FieldType/Url/Value.php @@ -4,43 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\Url; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for Url field type. + * Value for the Url field type. */ class Value extends BaseValue { - /** - * Link content. - * - * @var string|null - */ - public $link; - - /** - * Text content. - * - * @var string|null - */ - public $text; - - /** - * Construct a new Value object and initialize it with its $link and optional $text. - * - * @param string $link - * @param string $text - */ - public function __construct($link = null, $text = null) - { - $this->link = $link; - $this->text = $text; + public function __construct( + public readonly ?string $link = null, + public readonly ?string $text = null + ) { + parent::__construct(); } - public function __toString() + public function __toString(): string { return (string)$this->link; } diff --git a/src/lib/FieldType/User/Type.php b/src/lib/FieldType/User/Type.php index 1d4b04f6c2..569075bb81 100644 --- a/src/lib/FieldType/User/Type.php +++ b/src/lib/FieldType/User/Type.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\User; @@ -15,6 +16,7 @@ use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\PasswordHashService; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\FieldType\FieldType; use Ibexa\Core\FieldType\ValidationError; use Ibexa\Core\FieldType\Value as BaseValue; @@ -38,7 +40,7 @@ class Type extends FieldType implements TranslationContainerInterface public const USERNAME_PATTERN = 'UsernamePattern'; /** @var array */ - protected $settingsSchema = [ + protected array $settingsSchema = [ self::PASSWORD_TTL_SETTING => [ 'type' => 'int', 'default' => null, @@ -58,7 +60,7 @@ class Type extends FieldType implements TranslationContainerInterface ]; /** @var array */ - protected $validatorConfigurationSchema = [ + protected array $validatorConfigurationSchema = [ 'PasswordValueValidator' => [ 'requireAtLeastOneUpperCaseCharacter' => [ 'type' => 'int', @@ -128,33 +130,17 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin return (string)$value->login; } - /** - * Indicates if the field definition of this type can appear only once in the same ContentType. - * - * @return bool - */ public function isSingular(): bool { return true; } - /** - * Indicates if the field definition of this type can be added to a ContentType with Content instances. - * - * @return bool - */ public function onlyEmptyInstance(): bool { return true; } - /** - * Returns the fallback default value of field type when no such default - * value is provided in the field definition in content types. - * - * @return \Ibexa\Core\FieldType\User\Value - */ - public function getEmptyValue() + public function getEmptyValue(): Value { return new Value(); } @@ -187,22 +173,12 @@ protected function checkValueStructure(BaseValue $value) // Does nothing } - /** - * {@inheritdoc} - */ - protected function getSortInfo(BaseValue $value): bool + protected function getSortInfo(SPIValue $value): false { return false; } - /** - * Converts an $hash to the Value defined by the field type. - * - * @param mixed $hash - * - * @return \Ibexa\Core\FieldType\User\Value $value - */ - public function fromHash($hash) + public function fromHash(mixed $hash): Value { if ($hash === null) { return $this->getEmptyValue(); @@ -216,13 +192,11 @@ public function fromHash($hash) } /** - * Converts a $Value to a hash. - * * @param \Ibexa\Core\FieldType\User\Value $value * - * @return mixed + * @return array|null */ - public function toHash(SPIValue $value) + public function toHash(SPIValue $value): ?array { if ($this->isEmptyValue($value)) { return null; @@ -236,10 +210,13 @@ public function toHash(SPIValue $value) return $hash; } - public function toPersistenceValue(SPIValue $value) + /** + * @param \Ibexa\Core\FieldType\User\Value $value + */ + public function toPersistenceValue(SPIValue $value): FieldValue { $value->passwordHashType = $this->getPasswordHashTypeForPersistenceValue($value); - if ($value->plainPassword) { + if (!empty($value->plainPassword)) { $value->passwordHash = $this->passwordHashService->createPasswordHash( $value->plainPassword, $value->passwordHashType @@ -258,7 +235,7 @@ public function toPersistenceValue(SPIValue $value) private function getPasswordHashTypeForPersistenceValue(SPIValue $value): int { - if (null === $value->passwordHashType) { + if (!isset($value->passwordHashType)) { return $this->passwordHashService->getDefaultHashType(); } @@ -270,38 +247,40 @@ private function getPasswordHashTypeForPersistenceValue(SPIValue $value): int } /** - * Converts a persistence $fieldValue to a Value. - * - * This method builds a field type value from the $data and $externalData properties. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\FieldValue $fieldValue - * - * @return \Ibexa\Core\FieldType\User\Value + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function fromPersistenceValue(FieldValue $fieldValue) + public function fromPersistenceValue(FieldValue $fieldValue): Value { - return $this->acceptValue($fieldValue->externalData); + $value = $this->acceptValue($fieldValue->externalData); + if (!$value instanceof Value) { + throw new InvalidArgumentException( + '$fieldValue', + 'The given FieldValue does not contain proper User field type external data' + ); + } + + return $value; } /** * Validates a field based on the validators in the field definition. * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException - * - * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field - * @param \Ibexa\Core\FieldType\User\Value $fieldValue The field value for which an action is performed + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition $fieldDef The field definition of the field + * @param \Ibexa\Core\FieldType\User\Value $value The field value for which an action is performed * * @return \Ibexa\Contracts\Core\FieldType\ValidationError[] + * + *@throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) + public function validate(FieldDefinition $fieldDef, SPIValue $value): array { $errors = []; - if ($this->isEmptyValue($fieldValue)) { + if ($this->isEmptyValue($value)) { return $errors; } - if (!is_string($fieldValue->login) || empty($fieldValue->login)) { + if (!is_string($value->login) || empty($value->login)) { $errors[] = new ValidationError( 'Login required', null, @@ -310,9 +289,9 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - $pattern = sprintf('/%s/', $fieldDefinition->fieldSettings[self::USERNAME_PATTERN]); - $loginFormatValid = preg_match($pattern, $fieldValue->login); - if (!$fieldValue->hasStoredLogin && !$loginFormatValid) { + $pattern = sprintf('/%s/', $fieldDef->fieldSettings[self::USERNAME_PATTERN]); + $loginFormatValid = preg_match($pattern, $value->login); + if (!$value->hasStoredLogin && !$loginFormatValid) { $errors[] = new ValidationError( 'Invalid login format', null, @@ -321,23 +300,23 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - if (!is_string($fieldValue->email) || empty($fieldValue->email)) { + if (!is_string($value->email) || empty($value->email)) { $errors[] = new ValidationError( 'Email required', null, [], 'email' ); - } elseif (false === filter_var($fieldValue->email, FILTER_VALIDATE_EMAIL)) { + } elseif (false === filter_var($value->email, FILTER_VALIDATE_EMAIL)) { $errors[] = new ValidationError( "The given e-mail '%email%' is invalid", null, - ['%email%' => $fieldValue->email], + ['%email%' => $value->email], 'email' ); } - if (!$fieldValue->hasStoredLogin && (!is_string($fieldValue->plainPassword) || empty($fieldValue->plainPassword))) { + if (!$value->hasStoredLogin && (!is_string($value->plainPassword) || empty($value->plainPassword))) { $errors[] = new ValidationError( 'Password required', null, @@ -346,7 +325,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - if (!is_bool($fieldValue->enabled)) { + if (!is_bool($value->enabled)) { $errors[] = new ValidationError( 'Enabled must be boolean value', null, @@ -355,9 +334,9 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) ); } - if (!$fieldValue->hasStoredLogin && isset($fieldValue->login)) { + if (!$value->hasStoredLogin && isset($value->login)) { try { - $login = $fieldValue->login; + $login = $value->login; $this->userHandler->loadByLogin($login); // If you want to change this ValidationError message, please remember to change it also in Content Forms in lib/Validator/Constraints/FieldValueValidatorMessages class @@ -374,9 +353,9 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } } - if ($fieldDefinition->fieldSettings[self::REQUIRE_UNIQUE_EMAIL]) { + if ($fieldDef->fieldSettings[self::REQUIRE_UNIQUE_EMAIL]) { try { - $email = $fieldValue->email; + $email = $value->email; try { $user = $this->userHandler->loadByEmail($email); } catch (LogicException $exception) { @@ -384,7 +363,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } // Don't prevent email update - if (empty($user) || $user->id != $fieldValue->contentId) { + if (empty($user) || $user->id != $value->contentId) { // If you want to change this ValidationError message, please remember to change it also in Content Forms in lib/Validator/Constraints/FieldValueValidatorMessages class $errors[] = new ValidationError( "Email '%email%' is used by another user. You must enter a unique email.", @@ -400,19 +379,19 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) } } - if (!empty($fieldValue->plainPassword)) { + if (!empty($value->plainPassword)) { $passwordValidationErrors = $this->passwordValidator->validatePassword( - $fieldValue->plainPassword, - $fieldDefinition + $value->plainPassword, + $fieldDef ); $errors = array_merge($errors, $passwordValidationErrors); - if (!empty($fieldValue->passwordHash) && $this->isNewPasswordRequired($fieldDefinition)) { + if (!empty($value->passwordHash) && $this->isNewPasswordRequired($fieldDef)) { $isPasswordReused = $this->passwordHashService->isValidPassword( - $fieldValue->plainPassword, - $fieldValue->passwordHash, - $fieldValue->passwordHashType + $value->plainPassword, + $value->passwordHash, + $value->passwordHashType ); if ($isPasswordReused) { @@ -427,7 +406,7 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue) /** * {@inheritdoc} */ - public function validateValidatorConfiguration($validatorConfiguration) + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { $validationErrors = []; @@ -447,10 +426,7 @@ public function validateValidatorConfiguration($validatorConfiguration) return $validationErrors; } - /** - * {@inheritdoc} - */ - public function validateFieldSettings($fieldSettings) + public function validateFieldSettings(array $fieldSettings): array { $validationErrors = []; diff --git a/src/lib/FieldType/User/Value.php b/src/lib/FieldType/User/Value.php index 92eefb0355..67b0323434 100644 --- a/src/lib/FieldType/User/Value.php +++ b/src/lib/FieldType/User/Value.php @@ -4,84 +4,52 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\User; +use DateTimeImmutable; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for User field type. + * Value for the User field type. */ class Value extends BaseValue { /** * Has stored login. - * - * @var bool */ - public $hasStoredLogin; + public bool $hasStoredLogin; - /** - * Contentobject id. - * - * @var mixed - */ - public $contentId; + public int $contentId; - /** - * Login. - * - * @var string - */ - public $login; + public string $login; /** * Email. - * - * @var string */ - public $email; + public string $email; - /** - * Password hash. - * - * @var string - */ - public $passwordHash; + public string $passwordHash; - /** - * Password hash type. - * - * @var mixed - */ - public $passwordHashType; + public int $passwordHashType; - /** - * @var \DateTimeImmutable|null - */ - public $passwordUpdatedAt; + public ?DateTimeImmutable $passwordUpdatedAt; - /** - * Is enabled. - * - * @var bool - */ - public $enabled; + public bool $enabled; /** * Max login. - * - * @var int */ - public $maxLogin; + public int $maxLogin; /** - * @var string Write only property, takes a plain password for use when creating user or updating password. + * @var string Write-only property, takes a plain password for use when creating user or updating password. */ - public $plainPassword; + public string $plainPassword; - public function __toString() + public function __toString(): string { - return (string)$this->login; + return $this->login; } } diff --git a/src/lib/FieldType/Value.php b/src/lib/FieldType/Value.php index e5d1d80079..fd6bdd9de4 100644 --- a/src/lib/FieldType/Value.php +++ b/src/lib/FieldType/Value.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType; @@ -12,14 +13,13 @@ /** * Abstract class for all field value classes. - * A field value object is to be understood with associated field type. + * + * A field value object is associated with its field type. */ abstract class Value extends ValueObject implements ValueInterface { /** * Returns a string representation of the field value. - * - * @return string */ - abstract public function __toString(); + abstract public function __toString(): string; } diff --git a/src/lib/IO/ConfigScopeChangeAwareIOService.php b/src/lib/IO/ConfigScopeChangeAwareIOService.php index 1af4d53e6b..0f19e85b12 100644 --- a/src/lib/IO/ConfigScopeChangeAwareIOService.php +++ b/src/lib/IO/ConfigScopeChangeAwareIOService.php @@ -14,16 +14,16 @@ use Ibexa\Core\IO\Values\BinaryFileCreateStruct; use Ibexa\Core\MVC\Symfony\Event\ScopeChangeEvent; +/** + * @internal + */ class ConfigScopeChangeAwareIOService implements IOServiceInterface, ConfigScopeChangeSubscriber { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** @var \Ibexa\Core\IO\IOServiceInterface */ - private $innerIOService; + private IOServiceInterface $innerIOService; - /** @var string */ - private $prefixParameterName; + private string $prefixParameterName; public function __construct( ConfigResolverInterface $configResolver, @@ -38,27 +38,27 @@ public function __construct( $this->setPrefix($this->configResolver->getParameter($this->prefixParameterName)); } - public function setPrefix($prefix): void + public function setPrefix(string $prefix): void { $this->innerIOService->setPrefix($prefix); } - public function newBinaryCreateStructFromLocalFile($localFile): BinaryFileCreateStruct + public function newBinaryCreateStructFromLocalFile(string $localFile): BinaryFileCreateStruct { return $this->innerIOService->newBinaryCreateStructFromLocalFile($localFile); } - public function exists($binaryFileId): bool + public function exists(string $binaryFileId): bool { return $this->innerIOService->exists($binaryFileId); } - public function loadBinaryFile($binaryFileId): BinaryFile + public function loadBinaryFile(string $binaryFileId): BinaryFile { return $this->innerIOService->loadBinaryFile($binaryFileId); } - public function loadBinaryFileByUri($binaryFileUri): BinaryFile + public function loadBinaryFileByUri(string $binaryFileUri): BinaryFile { return $this->innerIOService->loadBinaryFileByUri($binaryFileUri); } @@ -73,17 +73,17 @@ public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) return $this->innerIOService->createBinaryFile($binaryFileCreateStruct); } - public function getUri($binaryFileId): string + public function getUri(string $binaryFileId): string { return $this->innerIOService->getUri($binaryFileId); } - public function getMimeType($binaryFileId): ?string + public function getMimeType(string $binaryFileId): ?string { return $this->innerIOService->getMimeType($binaryFileId); } - public function getFileInputStream(BinaryFile $binaryFile) + public function getFileInputStream(BinaryFile $binaryFile): mixed { return $this->innerIOService->getFileInputStream($binaryFile); } @@ -98,7 +98,7 @@ public function newBinaryCreateStructFromUploadedFile(array $uploadedFile): Bina return $this->innerIOService->newBinaryCreateStructFromUploadedFile($uploadedFile); } - public function deleteDirectory($path): void + public function deleteDirectory(string $path): void { $this->innerIOService->deleteDirectory($path); } diff --git a/src/lib/IO/Exception/BinaryFileNotFoundException.php b/src/lib/IO/Exception/BinaryFileNotFoundException.php index 01cc111543..1b5e251f7f 100644 --- a/src/lib/IO/Exception/BinaryFileNotFoundException.php +++ b/src/lib/IO/Exception/BinaryFileNotFoundException.php @@ -8,12 +8,12 @@ namespace Ibexa\Core\IO\Exception; -use Exception; use Ibexa\Core\Base\Exceptions\NotFoundException as BaseNotFoundException; +use Throwable; class BinaryFileNotFoundException extends BaseNotFoundException { - public function __construct(string $path, ?Exception $previous = null) + public function __construct(string $path, ?Throwable $previous = null) { parent::__construct('BinaryFile', $path, $previous); } diff --git a/src/lib/IO/Exception/IOException.php b/src/lib/IO/Exception/IOException.php index ef557d5159..6dbe03a8c1 100644 --- a/src/lib/IO/Exception/IOException.php +++ b/src/lib/IO/Exception/IOException.php @@ -4,18 +4,19 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\Exception; -use Exception; use RuntimeException; +use Throwable; /** * General IO exception. */ class IOException extends RuntimeException { - public function __construct($message, Exception $e = null) + public function __construct(string $message, ?Throwable $e = null) { parent::__construct($message, 0, $e); } diff --git a/src/lib/IO/FilePathNormalizer/Flysystem.php b/src/lib/IO/FilePathNormalizer/Flysystem.php index 9fade42eea..c1ecb4fe5b 100644 --- a/src/lib/IO/FilePathNormalizer/Flysystem.php +++ b/src/lib/IO/FilePathNormalizer/Flysystem.php @@ -14,7 +14,7 @@ final class Flysystem implements FilePathNormalizerInterface { - private const HASH_PATTERN = '/^[0-9a-f]{12}-/'; + private const string HASH_PATTERN = '/^[0-9a-f]{12}-/'; private SlugConverter $slugConverter; diff --git a/src/lib/IO/IOBinarydataHandler.php b/src/lib/IO/IOBinarydataHandler.php index 6b6e697403..34f9557d35 100644 --- a/src/lib/IO/IOBinarydataHandler.php +++ b/src/lib/IO/IOBinarydataHandler.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -19,29 +20,23 @@ interface IOBinarydataHandler * * @param \Ibexa\Contracts\Core\IO\BinaryFileCreateStruct $binaryFileCreateStruct * - * @throws \RuntimeException if an error occured creating the file + * @throws \RuntimeException if an error occurred creating the file */ - public function create(BinaryFileCreateStruct $binaryFileCreateStruct); + public function create(BinaryFileCreateStruct $binaryFileCreateStruct): void; /** - * Deletes the file $path. - * - * @param string $spiBinaryFileId + * Deletes the file by its $binaryFileId. * * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException If the file is not found */ - public function delete($spiBinaryFileId); + public function delete(string $binaryFileId): void; /** * Returns the binary content from $path. * - * @param $spiBinaryFileId - * * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException If $path is not found - * - * @return string */ - public function getContents($spiBinaryFileId); + public function getContents(string $spiBinaryFileId): string; /** * Returns a read-only, binary file resource to $path. @@ -52,30 +47,22 @@ public function getContents($spiBinaryFileId); * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function getResource($spiBinaryFileId); + public function getResource(string $spiBinaryFileId): mixed; /** * Returns the public URI for $path. - * - * @param string $spiBinaryFileId - * - * @return string */ - public function getUri($spiBinaryFileId); + public function getUri(string $spiBinaryFileId): string; /** * Returns the id in $binaryFileUri. - * - * @param string $binaryFileUri - * - * @return string */ - public function getIdFromUri($binaryFileUri); + public function getIdFromUri(string $binaryFileUri): string; /** * Deletes the directory $spiPath and all of its contents. * - * @param string $spiPath + * @param string $path */ - public function deleteDirectory($spiPath); + public function deleteDirectory(string $path): void; } diff --git a/src/lib/IO/IOBinarydataHandler/Flysystem.php b/src/lib/IO/IOBinarydataHandler/Flysystem.php index 6e8463207c..72c84fd5a5 100644 --- a/src/lib/IO/IOBinarydataHandler/Flysystem.php +++ b/src/lib/IO/IOBinarydataHandler/Flysystem.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\IOBinarydataHandler; @@ -49,16 +50,16 @@ public function create(BinaryFileCreateStruct $binaryFileCreateStruct): void } } - public function delete($spiBinaryFileId): void + public function delete(string $binaryFileId): void { try { - $this->filesystem->delete($spiBinaryFileId); + $this->filesystem->delete($binaryFileId); } catch (FilesystemException $e) { - throw new BinaryFileNotFoundException($spiBinaryFileId, $e); + throw new BinaryFileNotFoundException($binaryFileId, $e); } } - public function getContents($spiBinaryFileId): string + public function getContents(string $spiBinaryFileId): string { try { return $this->filesystem->read($spiBinaryFileId); @@ -67,7 +68,7 @@ public function getContents($spiBinaryFileId): string } } - public function getResource($spiBinaryFileId) + public function getResource(string $spiBinaryFileId): mixed { try { return $this->filesystem->readStream($spiBinaryFileId); @@ -76,14 +77,14 @@ public function getResource($spiBinaryFileId) } } - public function getUri($spiBinaryFileId): string + public function getUri(string $spiBinaryFileId): string { return null !== $this->urlDecorator ? $this->urlDecorator->decorate($spiBinaryFileId) : '/' . $spiBinaryFileId; } - public function getIdFromUri($binaryFileUri): string + public function getIdFromUri(string $binaryFileUri): string { if (isset($this->urlDecorator)) { return $this->urlDecorator->undecorate($binaryFileUri); @@ -92,12 +93,12 @@ public function getIdFromUri($binaryFileUri): string return ltrim($binaryFileUri, '/'); } - public function deleteDirectory($spiPath): void + public function deleteDirectory(string $path): void { try { - $this->filesystem->deleteDirectory($spiPath); + $this->filesystem->deleteDirectory($path); } catch (FilesystemException $e) { - throw new IOException("'Unable to delete directory '$spiPath'", $e); + throw new IOException("'Unable to delete directory '$path'", $e); } } } diff --git a/src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php b/src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php index c4ab5a7ebb..53ca49f738 100644 --- a/src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php +++ b/src/lib/IO/IOBinarydataHandler/SiteAccessDependentBinaryDataHandler.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\IOBinarydataHandler; @@ -17,12 +18,14 @@ */ final class SiteAccessDependentBinaryDataHandler implements IOBinaryDataHandler { - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry */ - private $dataHandlerRegistry; + /** @phpstan-var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler> */ + private HandlerRegistry $dataHandlerRegistry; + /** + * @phpstan-param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler> $dataHandlerRegistry + */ public function __construct( ConfigResolverInterface $configResolver, HandlerRegistry $dataHandlerRegistry @@ -38,38 +41,38 @@ private function getHandler(): IOBinarydataHandler ); } - public function create(BinaryFileCreateStruct $binaryFileCreateStruct) + public function create(BinaryFileCreateStruct $binaryFileCreateStruct): void { - return $this->getHandler()->create($binaryFileCreateStruct); + $this->getHandler()->create($binaryFileCreateStruct); } - public function delete($spiBinaryFileId) + public function delete(string $binaryFileId): void { - return $this->getHandler()->delete($spiBinaryFileId); + $this->getHandler()->delete($binaryFileId); } - public function getContents($spiBinaryFileId) + public function getContents(string $spiBinaryFileId): string { return $this->getHandler()->getContents($spiBinaryFileId); } - public function getResource($spiBinaryFileId) + public function getResource(string $spiBinaryFileId): mixed { return $this->getHandler()->getResource($spiBinaryFileId); } - public function getUri($spiBinaryFileId) + public function getUri(string $spiBinaryFileId): string { return $this->getHandler()->getUri($spiBinaryFileId); } - public function getIdFromUri($binaryFileUri) + public function getIdFromUri(string $binaryFileUri): string { return $this->getHandler()->getIdFromUri($binaryFileUri); } - public function deleteDirectory($spiPath) + public function deleteDirectory(string $path): void { - return $this->getHandler()->deleteDirectory($spiPath); + $this->getHandler()->deleteDirectory($path); } } diff --git a/src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php b/src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php index b0b570f2c2..4f1c438c03 100644 --- a/src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php +++ b/src/lib/IO/IOBinarydataHandler/SiteAccessDependentMetadataHandler.php @@ -4,10 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\IOBinarydataHandler; use Ibexa\Bundle\IO\ApiLoader\HandlerRegistry; +use Ibexa\Contracts\Core\IO\BinaryFile; use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\IO\IOMetadataHandler; @@ -18,11 +20,14 @@ final class SiteAccessDependentMetadataHandler implements IOMetadataHandler { /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface $configResolver; - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry */ - private $dataHandlerRegistry; + /** @phpstan-var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler> */ + private HandlerRegistry $dataHandlerRegistry; + /** + * @phpstan-param \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler> $dataHandlerRegistry + */ public function __construct( ConfigResolverInterface $configResolver, HandlerRegistry $dataHandlerRegistry @@ -38,33 +43,33 @@ private function getHandler(): IOMetadataHandler ); } - public function create(BinaryFileCreateStruct $spiBinaryFileCreateStruct) + public function create(BinaryFileCreateStruct $spiBinaryFileCreateStruct): BinaryFile { return $this->getHandler()->create($spiBinaryFileCreateStruct); } - public function delete($spiBinaryFileId) + public function delete(string $binaryFileId): void { - return $this->getHandler()->delete($spiBinaryFileId); + $this->getHandler()->delete($binaryFileId); } - public function load($spiBinaryFileId) + public function load(string $spiBinaryFileId): BinaryFile { return $this->getHandler()->load($spiBinaryFileId); } - public function exists($spiBinaryFileId) + public function exists(string $spiBinaryFileId): bool { return $this->getHandler()->exists($spiBinaryFileId); } - public function getMimeType($spiBinaryFileId) + public function getMimeType(string $spiBinaryFileId): string { return $this->getHandler()->getMimeType($spiBinaryFileId); } - public function deleteDirectory($spiPath) + public function deleteDirectory(string $path): void { - return $this->getHandler()->deleteDirectory($spiPath); + $this->getHandler()->deleteDirectory($path); } } diff --git a/src/lib/IO/IOMetadataHandler.php b/src/lib/IO/IOMetadataHandler.php index 8a8d468f92..3cfb1dd78a 100644 --- a/src/lib/IO/IOMetadataHandler.php +++ b/src/lib/IO/IOMetadataHandler.php @@ -4,13 +4,15 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; +use Ibexa\Contracts\Core\IO\BinaryFile; use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct; /** - * Provides reading & writing of files meta data (size, modification time...). + * Provides reading & writing of files meta-data (size, modification time...). */ interface IOMetadataHandler { @@ -19,49 +21,35 @@ interface IOMetadataHandler * * @param \Ibexa\Contracts\Core\IO\BinaryFileCreateStruct $spiBinaryFileCreateStruct * - * @return \Ibexa\Contracts\Core\IO\BinaryFile - * - * @throws \RuntimeException if an error occured creating the file + * @throws \RuntimeException if an error occurred creating the file */ - public function create(BinaryFileCreateStruct $spiBinaryFileCreateStruct); + public function create(BinaryFileCreateStruct $spiBinaryFileCreateStruct): BinaryFile; /** - * Deletes file $spiBinaryFileId. + * Deletes file by its $binaryFileId. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If $spiBinaryFileId is not found - * - * @param string $spiBinaryFileId */ - public function delete($spiBinaryFileId); + public function delete(string $binaryFileId): void; /** * Loads and returns metadata for $spiBinaryFileId. * - * @param string $spiBinaryFileId - * - * @return \Ibexa\Contracts\Core\IO\BinaryFile - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function load($spiBinaryFileId); + public function load(string $spiBinaryFileId): BinaryFile; /** * Checks if a file $spiBinaryFileId exists. - * - * @param string $spiBinaryFileId - * - * @return bool */ - public function exists($spiBinaryFileId); + public function exists(string $spiBinaryFileId): bool; /** * Returns the file's mimetype. Example: text/plain. * - * @param $spiBinaryFileId - * - * @return string + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function getMimeType($spiBinaryFileId); + public function getMimeType(string $spiBinaryFileId): string; - public function deleteDirectory($spiPath); + public function deleteDirectory(string $path): void; } diff --git a/src/lib/IO/IOMetadataHandler/Flysystem.php b/src/lib/IO/IOMetadataHandler/Flysystem.php index 678d10f4ec..c50d184474 100644 --- a/src/lib/IO/IOMetadataHandler/Flysystem.php +++ b/src/lib/IO/IOMetadataHandler/Flysystem.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\IOMetadataHandler; @@ -41,6 +42,7 @@ public function setLogger(LoggerInterface $logger): void * Only reads & returns metadata, since the binary data handler took care of creating the file already. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \DateMalformedStringException */ public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct): IOBinaryFile { @@ -49,23 +51,25 @@ public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct): IO /** * Does really nothing, the binary data handler takes care of it. - * - * @param $spiBinaryFileId */ - public function delete($spiBinaryFileId) + public function delete(string $binaryFileId): void { } - public function load($spiBinaryFileId): IOBinaryFile + /** + * @throws \DateMalformedStringException + * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException + */ + public function load(string $spiBinaryFileId): IOBinaryFile { try { return $this->getIOBinaryFile($spiBinaryFileId); - } catch (FilesystemException $e) { + } catch (FilesystemException) { throw new BinaryFileNotFoundException($spiBinaryFileId); } } - public function exists($spiBinaryFileId): bool + public function exists(string $spiBinaryFileId): bool { try { return $this->filesystem->fileExists($spiBinaryFileId); @@ -84,7 +88,7 @@ public function exists($spiBinaryFileId): bool } } - public function getMimeType($spiBinaryFileId): string + public function getMimeType(string $spiBinaryFileId): string { try { return $this->filesystem->mimeType($spiBinaryFileId); @@ -99,12 +103,13 @@ public function getMimeType($spiBinaryFileId): string /** * Does nothing, as the binary data handler takes care of it. */ - public function deleteDirectory($spiPath) + public function deleteDirectory(string $path): void { } /** * @throws \League\Flysystem\FilesystemException + * @throws \DateMalformedStringException */ private function getIOBinaryFile(string $spiBinaryFileId): IOBinaryFile { diff --git a/src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php b/src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php index 724516ed85..a2ad486ede 100644 --- a/src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php +++ b/src/lib/IO/IOMetadataHandler/LegacyDFSCluster.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\IOMetadataHandler; @@ -12,7 +13,6 @@ use Doctrine\DBAL\Exception; use Ibexa\Contracts\Core\IO\BinaryFile as SPIBinaryFile; use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct; -use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\IO\Exception\BinaryFileNotFoundException; use Ibexa\Core\IO\IOMetadataHandler; use Ibexa\Core\IO\UrlDecorator; @@ -21,20 +21,20 @@ * Manages IO metadata in a mysql table, ibexa_dfs_file. * * It will prevent simultaneous writes to the same file. + * + * @phpstan-type TLegacyDFSBinaryFileData array{id: string, name_hash: string, name: string, name_trunk: string, datatype: string, scope: string, size: int, mtime: int, expired: bool, status: bool} */ class LegacyDFSCluster implements IOMetadataHandler { public const string DFS_FILE_TABLE = 'ibexa_dfs_file'; - /** @var \Doctrine\DBAL\Connection */ - private $db; + private Connection $db; - /** @var \Ibexa\Core\IO\UrlDecorator */ - private $urlDecorator; + private ?UrlDecorator $urlDecorator; /** * @param \Doctrine\DBAL\Connection $connection Doctrine DBAL connection - * @param \Ibexa\Core\IO\UrlDecorator $urlDecorator The URL decorator used to add a prefix to files path + * @param \Ibexa\Core\IO\UrlDecorator|null $urlDecorator The URL decorator used to add a prefix to files path */ public function __construct(Connection $connection, UrlDecorator $urlDecorator = null) { @@ -49,18 +49,11 @@ public function __construct(Connection $connection, UrlDecorator $urlDecorator = * * @return \Ibexa\Contracts\Core\IO\BinaryFile * - *@throws \RuntimeException if a DBAL error occurs - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException if the $binaryFileCreateStruct is invalid - * - * @since 6.10 The mtime of the $binaryFileCreateStruct must be a DateTime, as specified in the struct doc. + * @throws \Doctrine\DBAL\Exception */ - public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct) + public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct): SPIBinaryFile { - if (!($spiBinaryFileCreateStruct->mtime instanceof DateTime)) { - throw new InvalidArgumentException('$binaryFileCreateStruct', 'Property \'mtime\' must be a DateTime'); - } - - $path = (string)$this->addPrefix($spiBinaryFileCreateStruct->id); + $path = $this->addPrefix($spiBinaryFileCreateStruct->id); $params = [ 'name' => $path, 'name_hash' => md5($path), @@ -90,13 +83,14 @@ public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct) /** * Deletes file $spiBinaryFileId. * - * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException If $spiBinaryFileId is not found + * @param string $binaryFileId * - * @param string $spiBinaryFileId + * @throws \Doctrine\DBAL\Exception + * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException If $spiBinaryFileId is not found */ - public function delete($spiBinaryFileId) + public function delete(string $binaryFileId): void { - $path = (string)$this->addPrefix($spiBinaryFileId); + $path = (string)$this->addPrefix($binaryFileId); // Unlike the legacy cluster, the file is directly deleted. It was inherited from the DB cluster anyway $affectedRows = (int)$this->db->delete(self::DFS_FILE_TABLE, [ @@ -112,16 +106,13 @@ public function delete($spiBinaryFileId) /** * Loads and returns metadata for $spiBinaryFileId. * - * @param string $spiBinaryFileId - * - * @return \Ibexa\Contracts\Core\IO\BinaryFile - * + * @throws \DateMalformedStringException * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException if no row is found for $spiBinaryFileId * @throws \Doctrine\DBAL\Exception Any unhandled DBAL exception */ - public function load($spiBinaryFileId) + public function load(string $spiBinaryFileId): SPIBinaryFile { - $path = (string)$this->addPrefix($spiBinaryFileId); + $path = $this->addPrefix($spiBinaryFileId); $queryBuilder = $this->db->createQueryBuilder(); $result = $queryBuilder @@ -148,6 +139,7 @@ public function load($spiBinaryFileId) throw new BinaryFileNotFoundException($path); } + /** @phpstan-var TLegacyDFSBinaryFileData $row */ $row = $result->fetchAssociative() + ['id' => $spiBinaryFileId]; return $this->mapArrayToSPIBinaryFile($row); @@ -156,16 +148,11 @@ public function load($spiBinaryFileId) /** * Checks if a file $spiBinaryFileId exists. * - * @param string $spiBinaryFileId - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException * @throws \Doctrine\DBAL\Exception Any unhandled DBAL exception - * - * @return bool */ - public function exists($spiBinaryFileId): bool + public function exists(string $spiBinaryFileId): bool { - $path = (string)$this->addPrefix($spiBinaryFileId); + $path = $this->addPrefix($spiBinaryFileId); $queryBuilder = $this->db->createQueryBuilder(); $result = $queryBuilder @@ -191,12 +178,7 @@ public function exists($spiBinaryFileId): bool return $result->rowCount() === 1; } - /** - * @param \Ibexa\Contracts\Core\IO\BinaryFileCreateStruct $binaryFileCreateStruct - * - * @return mixed - */ - protected function getNameTrunk(SPIBinaryFileCreateStruct $binaryFileCreateStruct) + protected function getNameTrunk(SPIBinaryFileCreateStruct $binaryFileCreateStruct): string { return $this->addPrefix($binaryFileCreateStruct->id); } @@ -215,25 +197,14 @@ protected function getScope(SPIBinaryFileCreateStruct $binaryFileCreateStruct): { [$filePrefix] = explode('/', $binaryFileCreateStruct->id); - switch ($filePrefix) { - case 'images': - return 'image'; - - case 'original': - return 'binaryfile'; - } - - return 'UNKNOWN_SCOPE'; + return match ($filePrefix) { + 'images' => 'image', + 'original' => 'binaryfile', + default => 'UNKNOWN_SCOPE', + }; } - /** - * Adds the internal prefix string to $id. - * - * @param string $id - * - * @return string prefixed id - */ - protected function addPrefix($id) + protected function addPrefix(string $id): string { return isset($this->urlDecorator) ? $this->urlDecorator->decorate($id) : $id; } @@ -241,18 +212,18 @@ protected function addPrefix($id) /** * Removes the internal prefix string from $prefixedId. * - * @param string $prefixedId - * * @return string the id without the prefix - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryFileIdException if the prefix isn't found in $prefixedId */ - protected function removePrefix($prefixedId) + protected function removePrefix(string $prefixedId): string { return isset($this->urlDecorator) ? $this->urlDecorator->undecorate($prefixedId) : $prefixedId; } - public function getMimeType($spiBinaryFileId) + /** + * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException + * @throws \Doctrine\DBAL\Exception + */ + public function getMimeType(string $spiBinaryFileId): string { $queryBuilder = $this->db->createQueryBuilder(); $result = $queryBuilder @@ -265,10 +236,11 @@ public function getMimeType($spiBinaryFileId) ->executeQuery() ; - if ($result->rowCount() == 0) { + if ($result->rowCount() === 0) { throw new BinaryFileNotFoundException($spiBinaryFileId); } + /** @var array{datatype: string} $row */ $row = $result->fetchAssociative(); return $row['datatype']; @@ -277,9 +249,11 @@ public function getMimeType($spiBinaryFileId) /** * Delete directory and all the content under specified directory. * - * @param string $spiPath SPI Path, not prefixed by URL decoration + * @param string $path persistence path, not prefixed by URL decoration + * + * @throws \Doctrine\DBAL\Exception */ - public function deleteDirectory($spiPath) + public function deleteDirectory(string $path): void { $query = $this->db->createQueryBuilder(); $query @@ -288,19 +262,19 @@ public function deleteDirectory($spiPath) ->setParameter('esc', '\\') ->setParameter( 'spiPath', - addcslashes($this->addPrefix(rtrim($spiPath, '/')), '%_') . '/%' + addcslashes($this->addPrefix(rtrim($path, '/')), '%_') . '/%' ); $query->executeStatement(); } /** - * Maps an array of data base properties (id, size, mtime, datatype, md5_path, path...) to an SPIBinaryFile object. + * Maps an array of database properties (id, size, mtime, datatype, md5_path, path...) to an SPIBinaryFile object. * - * @param array $properties database properties array + * @param array{id: string, size: int, mtime: int} $properties database properties array * - * @return \Ibexa\Contracts\Core\IO\BinaryFile + * @throws \DateMalformedStringException */ - protected function mapArrayToSPIBinaryFile(array $properties) + protected function mapArrayToSPIBinaryFile(array $properties): SPIBinaryFile { $spiBinaryFile = new SPIBinaryFile(); $spiBinaryFile->id = $properties['id']; @@ -310,12 +284,7 @@ protected function mapArrayToSPIBinaryFile(array $properties) return $spiBinaryFile; } - /** - * @param \Ibexa\Contracts\Core\IO\BinaryFileCreateStruct $binaryFileCreateStruct - * - * @return \Ibexa\Contracts\Core\IO\BinaryFile - */ - protected function mapSPIBinaryFileCreateStructToSPIBinaryFile(SPIBinaryFileCreateStruct $binaryFileCreateStruct) + protected function mapSPIBinaryFileCreateStructToSPIBinaryFile(SPIBinaryFileCreateStruct $binaryFileCreateStruct): SPIBinaryFile { $spiBinaryFile = new SPIBinaryFile(); $spiBinaryFile->id = $binaryFileCreateStruct->id; diff --git a/src/lib/IO/IOService.php b/src/lib/IO/IOService.php index c80a2822fd..e7af1dd60c 100644 --- a/src/lib/IO/IOService.php +++ b/src/lib/IO/IOService.php @@ -4,12 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; +use DateTime; use Exception; -use Ibexa\Contracts\Core\IO\BinaryFile as SPIBinaryFile; -use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct; +use Ibexa\Contracts\Core\IO\BinaryFile as PersistenceBinaryFile; +use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct as PersistenceBinaryFileCreateStruct; use Ibexa\Contracts\Core\IO\MimeTypeDetector; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\InvalidArgumentValue; @@ -17,44 +19,33 @@ use Ibexa\Core\IO\Exception\InvalidBinaryFileIdException; use Ibexa\Core\IO\Exception\InvalidBinaryPrefixException; use Ibexa\Core\IO\Exception\IOException; -use Ibexa\Core\IO\Values\BinaryFile; +use Ibexa\Core\IO\Values\BinaryFile as BinaryFileValue; use Ibexa\Core\IO\Values\BinaryFileCreateStruct; /** * The io service for managing binary files. + * + * @internal */ class IOService implements IOServiceInterface { - /** @var \Ibexa\Core\IO\IOBinarydataHandler */ - protected $binarydataHandler; - - /** @var \Ibexa\Core\IO\IOMetadataHandler */ - protected $metadataHandler; - - /** @var \Ibexa\Contracts\Core\IO\MimeTypeDetector */ - protected $mimeTypeDetector; - - /** @var array */ - protected $settings; - + /** + * @param array $settings + */ public function __construct( - IOMetadataHandler $metadataHandler, - IOBinarydataHandler $binarydataHandler, - MimeTypeDetector $mimeTypeDetector, - array $settings = [] + protected readonly IOMetadataHandler $metadataHandler, + protected readonly IOBinarydataHandler $binarydataHandler, + protected readonly MimeTypeDetector $mimeTypeDetector, + protected array $settings = [] ) { - $this->metadataHandler = $metadataHandler; - $this->binarydataHandler = $binarydataHandler; - $this->mimeTypeDetector = $mimeTypeDetector; - $this->settings = $settings; } - public function setPrefix($prefix) + public function setPrefix(string $prefix): void { $this->settings['prefix'] = $prefix; } - public function newBinaryCreateStructFromUploadedFile(array $uploadedFile) + public function newBinaryCreateStructFromUploadedFile(array $uploadedFile): BinaryFileCreateStruct { if (!is_string($uploadedFile['tmp_name']) || empty($uploadedFile['tmp_name'])) { throw new InvalidArgumentException('uploadedFile', "uploadedFile['tmp_name'] does not exist or has invalid value"); @@ -77,9 +68,9 @@ public function newBinaryCreateStructFromUploadedFile(array $uploadedFile) return $binaryCreateStruct; } - public function newBinaryCreateStructFromLocalFile($localFile) + public function newBinaryCreateStructFromLocalFile(string $localFile): BinaryFileCreateStruct { - if (empty($localFile) || !is_string($localFile)) { + if (empty($localFile)) { throw new InvalidArgumentException('localFile', 'localFile has an invalid value'); } @@ -92,24 +83,23 @@ public function newBinaryCreateStructFromLocalFile($localFile) throw new InvalidArgumentException('localFile', 'failed to get file resource'); } - $binaryCreateStruct = new BinaryFileCreateStruct( + return new BinaryFileCreateStruct( [ 'size' => filesize($localFile), 'inputStream' => $fileHandle, 'mimeType' => $this->mimeTypeDetector->getFromPath($localFile), ] ); - - return $binaryCreateStruct; } - public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) + public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct): BinaryFileValue { - if (empty($binaryFileCreateStruct->id) || !is_string($binaryFileCreateStruct->id)) { + if (empty($binaryFileCreateStruct->id)) { throw new InvalidArgumentValue('id', $binaryFileCreateStruct->id, 'BinaryFileCreateStruct'); } - if (!is_int($binaryFileCreateStruct->size) || $binaryFileCreateStruct->size < 0) { + // `fread` expects this to be a positive number + if ($binaryFileCreateStruct->size <= 0) { throw new InvalidArgumentValue('size', $binaryFileCreateStruct->size, 'BinaryFileCreateStruct'); } @@ -119,6 +109,12 @@ public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) if (!isset($binaryFileCreateStruct->mimeType)) { $buffer = fread($binaryFileCreateStruct->inputStream, $binaryFileCreateStruct->size); + if (false === $buffer) { + throw new InvalidArgumentException( + '$binaryFileCreateStruct', + "Failed to read the resource of BinaryFile with id = '$binaryFileCreateStruct->id'" + ); + } $binaryFileCreateStruct->mimeType = $this->mimeTypeDetector->getFromBuffer($buffer); unset($buffer); } @@ -128,7 +124,7 @@ public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) try { $this->binarydataHandler->create($spiBinaryCreateStruct); } catch (Exception $e) { - throw new IOException('An error occured when creating binary data', $e); + throw new IOException('An error occurred when creating binary data', $e); } $spiBinaryFile = $this->metadataHandler->create($spiBinaryCreateStruct); @@ -139,7 +135,7 @@ public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) return $this->buildDomainBinaryFileObject($spiBinaryFile); } - public function deleteBinaryFile(BinaryFile $binaryFile) + public function deleteBinaryFile(BinaryFileValue $binaryFile): void { $this->checkBinaryFileId($binaryFile->id); $spiUri = $this->getPrefixedUri($binaryFile->id); @@ -153,7 +149,7 @@ public function deleteBinaryFile(BinaryFile $binaryFile) $this->binarydataHandler->delete($spiUri); } - public function loadBinaryFile($binaryFileId) + public function loadBinaryFile(string $binaryFileId): BinaryFileValue { $this->checkBinaryFileId($binaryFileId); @@ -169,7 +165,7 @@ public function loadBinaryFile($binaryFileId) return $this->buildDomainBinaryFileObject($spiBinaryFile); } - public function loadBinaryFileByUri($binaryFileUri) + public function loadBinaryFileByUri(string $binaryFileUri): BinaryFileValue { return $this->loadBinaryFile( $this->removeUriPrefix( @@ -178,7 +174,7 @@ public function loadBinaryFileByUri($binaryFileUri) ); } - public function getFileInputStream(BinaryFile $binaryFile) + public function getFileInputStream(BinaryFileValue $binaryFile): mixed { $this->checkBinaryFileId($binaryFile->id); @@ -187,7 +183,7 @@ public function getFileInputStream(BinaryFile $binaryFile) ); } - public function getFileContents(BinaryFile $binaryFile) + public function getFileContents(BinaryFileValue $binaryFile): string { $this->checkBinaryFileId($binaryFile->id); @@ -196,53 +192,47 @@ public function getFileContents(BinaryFile $binaryFile) ); } - public function getUri($binaryFileId) + public function getUri(string $binaryFileId): string { return $this->binarydataHandler->getUri($binaryFileId); } - public function getMimeType($binaryFileId) + public function getMimeType(string $binaryFileId): ?string { return $this->metadataHandler->getMimeType($this->getPrefixedUri($binaryFileId)); } - public function exists($binaryFileId) + public function exists(string $binaryFileId): bool { return $this->metadataHandler->exists($this->getPrefixedUri($binaryFileId)); } /** - * Generates SPI BinaryFileCreateStruct object from provided API BinaryFileCreateStruct object. - * - * @param \Ibexa\Core\IO\Values\BinaryFileCreateStruct $binaryFileCreateStruct - * - * @return \Ibexa\Contracts\Core\IO\BinaryFileCreateStruct + * Generates BinaryFileCreateStruct object from the provided API BinaryFileCreateStruct object. */ - protected function buildSPIBinaryFileCreateStructObject(BinaryFileCreateStruct $binaryFileCreateStruct) + protected function buildSPIBinaryFileCreateStructObject(BinaryFileCreateStruct $binaryFileCreateStruct): PersistenceBinaryFileCreateStruct { - $spiBinaryCreateStruct = new SPIBinaryFileCreateStruct(); + $spiBinaryCreateStruct = new PersistenceBinaryFileCreateStruct(); - $spiBinaryCreateStruct->id = $this->getPrefixedUri($binaryFileCreateStruct->id); + $spiBinaryCreateStruct->id = $this->getPrefixedUri($binaryFileCreateStruct->id ?? ''); $spiBinaryCreateStruct->size = $binaryFileCreateStruct->size; $spiBinaryCreateStruct->setInputStream($binaryFileCreateStruct->inputStream); $spiBinaryCreateStruct->mimeType = $binaryFileCreateStruct->mimeType; - $spiBinaryCreateStruct->mtime = new \DateTime(); + $spiBinaryCreateStruct->mtime = new DateTime(); return $spiBinaryCreateStruct; } /** - * Generates API BinaryFile object from provided SPI BinaryFile object. - * - * @param \Ibexa\Contracts\Core\IO\BinaryFile $spiBinaryFile + * Generates an API BinaryFile object from the provided persistence layer BinaryFile object. * - * @return \Ibexa\Core\IO\Values\BinaryFile + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - protected function buildDomainBinaryFileObject(SPIBinaryFile $spiBinaryFile) + protected function buildDomainBinaryFileObject(PersistenceBinaryFile $spiBinaryFile): BinaryFileValue { - return new BinaryFile( + return new BinaryFileValue( [ - 'size' => (int)$spiBinaryFile->size, + 'size' => $spiBinaryFile->size, 'mtime' => $spiBinaryFile->mtime, 'id' => $this->removeUriPrefix($spiBinaryFile->id), 'uri' => $spiBinaryFile->uri, @@ -252,12 +242,8 @@ protected function buildDomainBinaryFileObject(SPIBinaryFile $spiBinaryFile) /** * Returns $uri prefixed with what is configured in the service. - * - * @param string $binaryFileId - * - * @return string */ - protected function getPrefixedUri($binaryFileId) + protected function getPrefixedUri(string $binaryFileId): string { $prefix = ''; if (isset($this->settings['prefix'])) { @@ -268,43 +254,32 @@ protected function getPrefixedUri($binaryFileId) } /** - * @param mixed $spiBinaryFileId - * - * @return string - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryPrefixException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - protected function removeUriPrefix($spiBinaryFileId) + protected function removeUriPrefix(string $binaryFileId): string { if (!isset($this->settings['prefix'])) { - return $spiBinaryFileId; + return $binaryFileId; } - if (strpos($spiBinaryFileId, $this->settings['prefix'] . '/') !== 0) { - throw new InvalidBinaryPrefixException($spiBinaryFileId, $this->settings['prefix'] . '/'); + if (!str_starts_with($binaryFileId, $this->settings['prefix'] . '/')) { + throw new InvalidBinaryPrefixException($binaryFileId, $this->settings['prefix'] . '/'); } - return substr($spiBinaryFileId, strlen($this->settings['prefix']) + 1); + return substr($binaryFileId, strlen($this->settings['prefix']) + 1); } /** - * @param string $binaryFileId - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryFileIdException If the id is invalid + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If the id is invalid */ - protected function checkBinaryFileId($binaryFileId) + protected function checkBinaryFileId(string $binaryFileId): void { - if (empty($binaryFileId) || !is_string($binaryFileId)) { + if (empty($binaryFileId)) { throw new InvalidBinaryFileIdException($binaryFileId); } } - /** - * Deletes a directory. - * - * @param string $path - */ - public function deleteDirectory($path) + public function deleteDirectory(string $path): void { $prefixedUri = $this->getPrefixedUri($path); $this->metadataHandler->deleteDirectory($prefixedUri); @@ -312,13 +287,9 @@ public function deleteDirectory($path) } /** - * Check if path is absolute, in terms of http or disk (incl if it contains driver letter on Win). - * - * @param string $path - * - * @return bool + * Check if a path is absolute, in terms of http or disk (incl if it contains a driver letter on Win). */ - protected function isAbsolutePath($path) + protected function isAbsolutePath(string $path): bool { return $path[0] === '/' || (PHP_OS === 'WINNT' && $path[1] === ':'); } diff --git a/src/lib/IO/IOServiceInterface.php b/src/lib/IO/IOServiceInterface.php index 0ad678c523..1caa489abc 100644 --- a/src/lib/IO/IOServiceInterface.php +++ b/src/lib/IO/IOServiceInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -16,137 +17,93 @@ interface IOServiceInterface { /** - * The the internal prefix added by the IO Service. - * - * @param string $prefix + * The internal prefix added by the IO Service. */ - public function setPrefix($prefix); + public function setPrefix(string $prefix): void; /** * Creates a BinaryFileCreateStruct object from $localFile. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException When given a non existing / unreadable file - * - * @param string $localFile Path to local file - * - * @return \Ibexa\Core\IO\Values\BinaryFileCreateStruct + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException When given a non-existing / unreadable file */ - public function newBinaryCreateStructFromLocalFile($localFile); + public function newBinaryCreateStructFromLocalFile(string $localFile): BinaryFileCreateStruct; /** * Checks if a Binary File with $binaryFileId exists. - * - * @param string $binaryFileId - * - * @return bool */ - public function exists($binaryFileId); + public function exists(string $binaryFileId): bool; /** * Loads the binary file with $id. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue If the id is invalid - * - * @param string $binaryFileId - * - * @return \Ibexa\Core\IO\Values\BinaryFile the file, or false if it doesn't exist - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no file identified by $binaryFileId exists - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue If $binaryFileId is invalid + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If the id is invalid + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If no file identified by $binaryFileId exists */ - public function loadBinaryFile($binaryFileId); + public function loadBinaryFile(string $binaryFileId): BinaryFile; /** * Loads the binary file with uri $uri. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue If the id is invalid - * - * @param string $binaryFileUri - * - * @return \Ibexa\Core\IO\Values\BinaryFile the file, or false if it doesn't exist - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no file identified by $binaryFileId exists + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If the id is invalid + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If no file identified by $binaryFileId exists */ - public function loadBinaryFileByUri($binaryFileUri); + public function loadBinaryFileByUri(string $binaryFileUri): BinaryFile; /** * Returns the content of the binary file. * - * @param \Ibexa\Core\IO\Values\BinaryFile $binaryFile - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If $binaryFile isn't found - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue - * - * @return string + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException If $binaryFile isn't found + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function getFileContents(BinaryFile $binaryFile); + public function getFileContents(BinaryFile $binaryFile): string; /** * Creates a binary file in the repository. * - * @param \Ibexa\Core\IO\Values\BinaryFileCreateStruct $binaryFileCreateStruct - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue - * - * @return \Ibexa\Core\IO\Values\BinaryFile The created BinaryFile object + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct); + public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct): BinaryFile; /** * Returns the public HTTP uri for $binaryFileId. - * - * @param string $binaryFileId - * - * @return string */ - public function getUri($binaryFileId); + public function getUri(string $binaryFileId): string; /** * Gets the mime-type of the BinaryFile. * * Example: text/xml * - * @param string $binaryFileId - * - * @return string|null + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function getMimeType($binaryFileId); + public function getMimeType(string $binaryFileId): ?string; /** * Returns a read (mode: rb) file resource to the binary file identified by $path. * - * @param \Ibexa\Core\IO\Values\BinaryFile $binaryFile - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue - * * @return resource + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function getFileInputStream(BinaryFile $binaryFile); + public function getFileInputStream(BinaryFile $binaryFile): mixed; /** * Deletes the BinaryFile with $id. * - * @param \Ibexa\Core\IO\Values\BinaryFile $binaryFile - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function deleteBinaryFile(BinaryFile $binaryFile); + public function deleteBinaryFile(BinaryFile $binaryFile): void; /** * Creates a BinaryFileCreateStruct object from the uploaded file $uploadedFile. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException When given an invalid uploaded file - * - * @param array $uploadedFile The $_POST hash of an uploaded file + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException When given an invalid uploaded file * - * @return \Ibexa\Core\IO\Values\BinaryFileCreateStruct + * @param array $uploadedFile The $_POST hash of an uploaded file */ - public function newBinaryCreateStructFromUploadedFile(array $uploadedFile); + public function newBinaryCreateStructFromUploadedFile(array $uploadedFile): BinaryFileCreateStruct; - /** - * Deletes a directory. - * - * @param string $path - */ - public function deleteDirectory($path); + public function deleteDirectory(string $path): void; } diff --git a/src/lib/IO/MimeTypeDetector/FileInfo.php b/src/lib/IO/MimeTypeDetector/FileInfo.php index 8ca0b1cc04..bbc7bec956 100644 --- a/src/lib/IO/MimeTypeDetector/FileInfo.php +++ b/src/lib/IO/MimeTypeDetector/FileInfo.php @@ -4,19 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO\MimeTypeDetector; +use finfo; +use Ibexa\Contracts\Core\Exception\InvalidArgumentException; use Ibexa\Contracts\Core\IO\MimeTypeDetector; class FileInfo implements MimeTypeDetector { /** * Magic FileInfo object. - * - * @var \finfo */ - protected $fileInfo; + protected finfo $fileInfo; /** * Checks for the required ext/fileinfo. @@ -30,25 +31,33 @@ public function __construct() } } - public function getFromPath($path): string|false + public function getFromPath(string $path): string { - return $this->getFileInfo()->file($path); + $fileInfo = $this->getFileInfo()->file($path); + if ($fileInfo === false) { + throw new InvalidArgumentException('$path', "Failed to get file information for the path '$path'"); + } + + return $fileInfo; } - public function getFromBuffer($path): string|false + public function getFromBuffer(string $buffer): string { - return $this->getFileInfo()->buffer($path); + $bufferInfo = $this->getFileInfo()->buffer($buffer); + if ($bufferInfo === false) { + throw new InvalidArgumentException('$path', 'Failed to get file information a string buffer'); + } + + return $bufferInfo; } /** * Creates a new (or re-uses) finfo object and returns it. - * - * @return \finfo */ - protected function getFileInfo() + protected function getFileInfo(): finfo { if (!isset($this->fileInfo)) { - $this->fileInfo = new \finfo(FILEINFO_MIME_TYPE); + $this->fileInfo = new finfo(FILEINFO_MIME_TYPE); } return $this->fileInfo; diff --git a/src/lib/IO/TolerantIOService.php b/src/lib/IO/TolerantIOService.php index c388b8026a..b2eb17907a 100644 --- a/src/lib/IO/TolerantIOService.php +++ b/src/lib/IO/TolerantIOService.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -12,7 +13,8 @@ use Ibexa\Core\IO\Exception\InvalidBinaryAbsolutePathException; use Ibexa\Core\IO\Values\BinaryFile; use Ibexa\Core\IO\Values\MissingBinaryFile; -use Psr\Log\LoggerInterface; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; /** * An extended IOService that tolerates physically missing files. @@ -20,56 +22,35 @@ * Meant to be used on a "broken" instance where the storage directory isn't in sync with the database. * * Note that it will still return false when exists() is used. + * + * @internal */ -class TolerantIOService extends IOService +class TolerantIOService extends IOService implements LoggerAwareInterface { - /** @var \Psr\Log\LoggerInterface */ - protected $logger; + use LoggerAwareTrait; - public function setLogger(LoggerInterface $logger = null) - { - $this->logger = $logger; - } - - /** - * Deletes $binaryFile. - * - * @param \Ibexa\Core\IO\Values\BinaryFile $binaryFile - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentValue If the binary file is invalid - * @throws \Ibexa\Core\IO\Exception\BinaryFileNotFoundException If the binary file isn't found - */ - public function deleteBinaryFile(BinaryFile $binaryFile) + public function deleteBinaryFile(BinaryFile $binaryFile): void { $this->checkBinaryFileId($binaryFile->id); $spiUri = $this->getPrefixedUri($binaryFile->id); try { $this->metadataHandler->delete($spiUri); - } catch (BinaryFileNotFoundException $e) { + } catch (BinaryFileNotFoundException) { $this->logMissingFile($binaryFile->uri); $logged = true; } try { $this->binarydataHandler->delete($spiUri); - } catch (BinaryFileNotFoundException $e) { + } catch (BinaryFileNotFoundException) { if (!isset($logged)) { $this->logMissingFile($binaryFile->uri); } } } - /** - * Loads the binary file with $binaryFileId. - * - * @param string $binaryFileId - * - * @return \Ibexa\Core\IO\Values\BinaryFile|\Ibexa\Core\IO\Values\MissingBinaryFile - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryAbsolutePathException - */ - public function loadBinaryFile($binaryFileId) + public function loadBinaryFile(string $binaryFileId): BinaryFile { $this->checkBinaryFileId($binaryFileId); @@ -79,7 +60,7 @@ public function loadBinaryFile($binaryFileId) try { $spiBinaryFile = $this->metadataHandler->load($this->getPrefixedUri($binaryFileId)); - } catch (BinaryFileNotFoundException $e) { + } catch (BinaryFileNotFoundException) { $this->logMissingFile($binaryFileId); return new MissingBinaryFile([ @@ -95,7 +76,7 @@ public function loadBinaryFile($binaryFileId) return $this->buildDomainBinaryFileObject($spiBinaryFile); } - public function loadBinaryFileByUri($binaryFileUri) + public function loadBinaryFileByUri(string $binaryFileUri): BinaryFile { $binaryFileId = $this->binarydataHandler->getIdFromUri($binaryFileUri); try { @@ -111,7 +92,7 @@ public function loadBinaryFileByUri($binaryFileUri) try { return $this->loadBinaryFile($binaryFileId); - } catch (BinaryFileNotFoundException $e) { + } catch (BinaryFileNotFoundException) { $this->logMissingFile($binaryFileUri); return new MissingBinaryFile([ @@ -121,11 +102,8 @@ public function loadBinaryFileByUri($binaryFileUri) } } - private function logMissingFile($id) + private function logMissingFile(string $id): void { - if (!isset($this->logger)) { - return; - } - $this->logger->info("BinaryFile with id $id not found"); + $this->logger?->info("BinaryFile with id $id not found"); } } diff --git a/src/lib/IO/UrlDecorator.php b/src/lib/IO/UrlDecorator.php index 3596534338..0e825ddc10 100644 --- a/src/lib/IO/UrlDecorator.php +++ b/src/lib/IO/UrlDecorator.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -14,19 +15,11 @@ interface UrlDecorator { /** * Decorates $uri. - * - * @param string $uri - * - * @return string Decorated string */ - public function decorate($uri); + public function decorate(string $uri): string; /** * Un-decorates decorated $uri. - * - * @param $uri - * - * @return string Un-decorated string */ - public function undecorate($uri); + public function undecorate(string $uri): string; } diff --git a/src/lib/IO/UrlDecorator/Prefix.php b/src/lib/IO/UrlDecorator/Prefix.php index 64576fa977..c27e4bc443 100644 --- a/src/lib/IO/UrlDecorator/Prefix.php +++ b/src/lib/IO/UrlDecorator/Prefix.php @@ -17,12 +17,8 @@ */ class Prefix implements UrlDecorator { - /** @var \Ibexa\Core\IO\IOConfigProvider */ - protected $ioConfigResolver; - - public function __construct(IOConfigProvider $IOConfigResolver) + public function __construct(protected readonly IOConfigProvider $ioConfigResolver) { - $this->ioConfigResolver = $IOConfigResolver; } public function getPrefix(): string @@ -32,30 +28,30 @@ public function getPrefix(): string return trim($prefix, '/') . '/'; } - public function decorate($id) + public function decorate(string $uri): string { $prefix = $this->getPrefix(); if (empty($prefix)) { - return $id; + return $uri; } - return $prefix . trim($id, '/'); + return $prefix . trim($uri, '/'); } /** * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - public function undecorate($url) + public function undecorate(string $uri): string { $prefix = $this->getPrefix(); if (empty($prefix)) { - return $url; + return $uri; } - if (strpos($url, $prefix) !== 0) { - throw new InvalidBinaryPrefixException($url, $prefix); + if (!str_starts_with($uri, $prefix)) { + throw new InvalidBinaryPrefixException($uri, $prefix); } - return trim(substr($url, strlen($prefix)), '/'); + return trim(substr($uri, strlen($prefix)), '/'); } } diff --git a/src/lib/IO/UrlRedecorator.php b/src/lib/IO/UrlRedecorator.php index ed4f470335..b8f57b11af 100644 --- a/src/lib/IO/UrlRedecorator.php +++ b/src/lib/IO/UrlRedecorator.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -12,11 +13,9 @@ */ class UrlRedecorator implements UrlRedecoratorInterface { - /** @var UrlDecorator */ - private $sourceDecorator; + private UrlDecorator $sourceDecorator; - /** @var UrlDecorator */ - private $targetDecorator; + private UrlDecorator $targetDecorator; public function __construct(UrlDecorator $sourceDecorator, UrlDecorator $targetDecorator) { @@ -24,14 +23,14 @@ public function __construct(UrlDecorator $sourceDecorator, UrlDecorator $targetD $this->targetDecorator = $targetDecorator; } - public function redecorateFromSource($uri) + public function redecorateFromSource(string $uri): string { return $this->targetDecorator->decorate( $this->sourceDecorator->undecorate($uri) ); } - public function redecorateFromTarget($uri) + public function redecorateFromTarget(string $uri): string { return $this->sourceDecorator->decorate( $this->targetDecorator->undecorate($uri) diff --git a/src/lib/IO/UrlRedecoratorInterface.php b/src/lib/IO/UrlRedecoratorInterface.php index dcd8f501b0..dc48ddb422 100644 --- a/src/lib/IO/UrlRedecoratorInterface.php +++ b/src/lib/IO/UrlRedecoratorInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\IO; @@ -12,38 +13,26 @@ * * ```php * $redecorator = new UrlRedecorator( - * new Prefix( 'a' ), - * new Prefix( 'b' ) + * new Prefix('a'), + * new Prefix('b') * ); * - * $redecorator->redecorateFromSource( 'a/url' ); + * $redecorator->redecorateFromSource('a/url'); * // 'b/url' * - * $redecorator->redecorateFromTarget( 'b/url' ); + * $redecorator->redecorateFromTarget('b/url'); * // 'a/url' * ``` */ interface UrlRedecoratorInterface { /** - * Redecorates $uri from source to target. - * - * @param string $uri - * - * @return string - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryFileIdException If $uri couldn't be interpreted b y the target decorator + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If $uri couldn't be interpreted by the target decorator */ - public function redecorateFromSource($uri); + public function redecorateFromSource(string $uri): string; /** - * Redecorates $uri from source to target. - * - * @param string $uri - * - * @return string - * - * @throws \Ibexa\Core\IO\Exception\InvalidBinaryFileIdException If $uri couldn't be interpreted b y the target decorator + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException If $uri couldn't be interpreted by the target decorator */ - public function redecorateFromTarget($uri); + public function redecorateFromTarget(string $uri): string; } diff --git a/src/lib/IO/Values/BinaryFileCreateStruct.php b/src/lib/IO/Values/BinaryFileCreateStruct.php index 353b5601fd..1f714b7009 100644 --- a/src/lib/IO/Values/BinaryFileCreateStruct.php +++ b/src/lib/IO/Values/BinaryFileCreateStruct.php @@ -16,31 +16,27 @@ class BinaryFileCreateStruct extends ValueObject { /** * URI the binary file should be stored to. - * - * @var string */ - public $id; + public ?string $id = null; /** * The size of the file. - * - * @var int */ - public $size; + public int $size; /** * the input stream. * * @var resource */ - public $inputStream; + public mixed $inputStream; /** - * The file's mime type + * The file's mime type. + * * If not provided, will be auto-detected by the IOService - * Example: text/xml. * - * @var string + * Example: text/xml. */ - public $mimeType; + public string $mimeType; } diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php index 21abc9ac49..866560c7d1 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php @@ -4,26 +4,26 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension; +use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; +use Ibexa\Contracts\Core\Variation\Values\Variation; use Ibexa\Contracts\Core\Variation\VariationHandler; use Ibexa\Core\FieldType\ImageAsset\AssetMapper; use Ibexa\Core\MVC\Exception\SourceImageNotFoundException; -use InvalidArgumentException; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class ImageExtension extends AbstractExtension { - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $imageVariationService; + private VariationHandler $imageVariationService; - /** @var \Ibexa\Core\FieldType\ImageAsset\AssetMapper */ - protected $assetMapper; + protected AssetMapper $assetMapper; public function __construct(VariationHandler $imageVariationService, AssetMapper $assetMapper) { @@ -49,42 +49,36 @@ public function getFunctions(): array /** * Returns the image variation object for $field/$versionInfo. - * - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field - * @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo - * @param string $variationName - * - * @return \Ibexa\Contracts\Core\Variation\Values\Variation|null */ - public function getImageVariation(Field $field, VersionInfo $versionInfo, $variationName) + public function getImageVariation(Field $field, VersionInfo $versionInfo, string $variationName): ?Variation { try { return $this->imageVariationService->getVariation($field, $versionInfo, $variationName); - } catch (InvalidVariationException $e) { + } catch (InvalidVariationException) { if (isset($this->logger)) { $this->logger->error("Couldn't get variation '{$variationName}' for image with id {$field->value->id}"); } - } catch (SourceImageNotFoundException $e) { + } catch (SourceImageNotFoundException) { if (isset($this->logger)) { $this->logger->error( "Couldn't create variation '{$variationName}' for image with id {$field->value->id} because source image can't be found" ); } - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { if (isset($this->logger)) { $this->logger->error( "Couldn't create variation '{$variationName}' for image with id {$field->value->id} because an image could not be created from the given input" ); } } + + return null; } /** * Return identifier of the field used to store Image Asset value. * * Typically used to create generic view of the Image Asset field. - * - * @return string */ public function getImageAssetContentFieldIdentifier(): string { diff --git a/src/lib/Repository/Values/ContentType/FieldType.php b/src/lib/Repository/Values/ContentType/FieldType.php index 022036cd73..9885059728 100644 --- a/src/lib/Repository/Values/ContentType/FieldType.php +++ b/src/lib/Repository/Values/ContentType/FieldType.php @@ -52,26 +52,7 @@ public function getName(Value $value, APIFieldDefinition $fieldDefinition, strin return $this->internalFieldType->getName($value, $fieldDefinition, $languageCode); } - /** - * Returns a schema for the settings expected by the FieldType. - * - * Returns an arbitrary value, representing a schema for the settings of - * the FieldType. - * - * Explanation: There are no possible generic schemas for defining settings - * input, which is why no schema for the return value of this method is - * defined. It is up to the implementer to define and document a schema for - * the return value and document it. In addition, it is necessary that all - * consumers of this interface (e.g. Public API, REST API, GUIs, ...) - * provide plugin mechanisms to hook adapters for the specific FieldType - * into. These adapters then need to be either shipped with the FieldType - * or need to be implemented by a third party. If there is no adapter - * available for a specific FieldType, it will not be usable with the - * consumer. - * - * @return mixed - */ - public function getSettingsSchema() + public function getSettingsSchema(): array { return $this->internalFieldType->getSettingsSchema(); } diff --git a/src/lib/Resources/settings/io.yml b/src/lib/Resources/settings/io.yml index ad98eb6b8c..046becf1fd 100644 --- a/src/lib/Resources/settings/io.yml +++ b/src/lib/Resources/settings/io.yml @@ -5,18 +5,18 @@ parameters: ibexa.core.io.flysystem.link_handling: !php/const \League\Flysystem\Local\LocalFilesystemAdapter::DISALLOW_LINKS services: - ibexa.core.io.service: - class: Ibexa\Core\IO\TolerantIOService + Ibexa\Core\IO\TolerantIOService: + autoconfigure: true lazy: true arguments: - - '@Ibexa\Core\IO\IOBinarydataHandler\SiteAccessDependentMetadataHandler' - - '@Ibexa\Core\IO\IOBinarydataHandler\SiteAccessDependentBinaryDataHandler' - - '@ibexa.core.io.mimeTypeDetector' - calls: - - [ setLogger, ["@?logger" ] ] + $metadataHandler: '@Ibexa\Core\IO\IOBinarydataHandler\SiteAccessDependentMetadataHandler' + $binarydataHandler: '@Ibexa\Core\IO\IOBinarydataHandler\SiteAccessDependentBinaryDataHandler' + $mimeTypeDetector: '@Ibexa\Core\IO\MimeTypeDetector\FileInfo' + + ibexa.core.io.service: + alias: Ibexa\Core\IO\TolerantIOService - Ibexa\Core\IO\MimeTypeDetector\FileInfo: - class: Ibexa\Core\IO\MimeTypeDetector\FileInfo + Ibexa\Core\IO\MimeTypeDetector\FileInfo: ~ ibexa.core.io.mimeTypeDetector: alias: Ibexa\Core\IO\MimeTypeDetector\FileInfo diff --git a/tests/bundle/Core/Imagine/AliasCleanerTest.php b/tests/bundle/Core/Imagine/AliasCleanerTest.php index 596e2381f2..9f0770546d 100644 --- a/tests/bundle/Core/Imagine/AliasCleanerTest.php +++ b/tests/bundle/Core/Imagine/AliasCleanerTest.php @@ -4,20 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; use Ibexa\Bundle\Core\Imagine\AliasCleaner; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class AliasCleanerTest extends TestCase { - /** @var \Ibexa\Bundle\Core\Imagine\AliasCleaner */ - private $aliasCleaner; + private AliasCleaner $aliasCleaner; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $resolver; + private ResolverInterface & MockObject $resolver; protected function setUp(): void { @@ -26,7 +26,10 @@ protected function setUp(): void $this->aliasCleaner = new AliasCleaner($this->resolver); } - public function testRemoveAliases() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testRemoveAliases(): void { $originalPath = 'foo/bar/test.jpg'; $this->resolver diff --git a/tests/bundle/Core/Imagine/AliasGeneratorTest.php b/tests/bundle/Core/Imagine/AliasGeneratorTest.php index a50dfafd07..4af07afe46 100644 --- a/tests/bundle/Core/Imagine/AliasGeneratorTest.php +++ b/tests/bundle/Core/Imagine/AliasGeneratorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -11,9 +12,11 @@ use Ibexa\Bundle\Core\Imagine\AliasGenerator; use Ibexa\Bundle\Core\Imagine\Variation\ImagineAwareAliasGenerator; use Ibexa\Contracts\Core\FieldType\Value as FieldTypeValue; +use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\Exceptions\InvalidVariationException; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Variation\Values\ImageVariation; +use Ibexa\Contracts\Core\Variation\VariationHandler; use Ibexa\Contracts\Core\Variation\VariationPathGenerator; use Ibexa\Core\FieldType\Image\Value as ImageValue; use Ibexa\Core\FieldType\TextLine\Value as TextLineValue; @@ -31,46 +34,38 @@ use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; use Liip\ImagineBundle\Imagine\Filter\FilterManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; -class AliasGeneratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\AliasGenerator + */ +final class AliasGeneratorTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Binary\Loader\LoaderInterface */ - private $dataLoader; + private LoaderInterface & MockObject $dataLoader; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Imagine\Filter\FilterManager */ - private $filterManager; + private FilterManager & MockObject $filterManager; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $ioResolver; + private ResolverInterface & MockObject $ioResolver; - /** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */ - private $filterConfiguration; + private FilterConfiguration $filterConfiguration; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Psr\Log\LoggerInterface */ - private $logger; + private LoggerInterface & MockObject $logger; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Imagine\Image\ImagineInterface */ - private $imagine; + private ImagineInterface & MockObject $imagine; - /** @var \Ibexa\Bundle\Core\Imagine\AliasGenerator */ - private $aliasGenerator; + private AliasGenerator $aliasGenerator; - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ - private $decoratedAliasGenerator; + private VariationHandler $decoratedAliasGenerator; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Imagine\Image\BoxInterface */ - private $box; + private BoxInterface & MockObject $box; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Imagine\Image\ImageInterface */ - private $image; + private ImageInterface & MockObject $image; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Core\IO\IOServiceInterface */ - private $ioService; + private IOServiceInterface & MockObject $ioService; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Contracts\Core\Variation\VariationPathGenerator */ - private $variationPathGenerator; + private VariationPathGenerator & MockObject $variationPathGenerator; protected function setUp(): void { @@ -105,11 +100,8 @@ protected function setUp(): void /** * @dataProvider supportsValueProvider - * - * @param \Ibexa\Contracts\Core\FieldType\Value $value - * @param bool $isSupported */ - public function testSupportsValue($value, $isSupported) + public function testSupportsValue(FieldTypeValue $value, bool $isSupported): void { self::assertSame($isSupported, $this->aliasGenerator->supportsValue($value)); } @@ -117,13 +109,11 @@ public function testSupportsValue($value, $isSupported) /** * Data provider for testSupportsValue. * - * @see testSupportsValue - * - * @return array + * @return array * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @see testSupportsValue */ - public function supportsValueProvider() + public function supportsValueProvider(): array { return [ [$this->createMock(FieldTypeValue::class), false], @@ -133,23 +123,26 @@ public function supportsValueProvider() ]; } - public function testGetVariationWrongValue() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationWrongValue(): void { - $this->expectException(\InvalidArgumentException::class); - $field = new Field([ - 'value' => $this->createMock(FieldTypeValue::class), - 'fieldDefIdentifier' => 'image_field', - ]); + 'value' => $this->createMock(FieldTypeValue::class), + 'fieldDefIdentifier' => 'image_field', + ]); + + $this->expectException(InvalidArgumentException::class); $this->aliasGenerator->getVariation($field, new VersionInfo(), 'foo'); } /** * Test obtaining Image Variation that hasn't been stored yet. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationNotStored() + public function testGetVariationNotStored(): void { $originalPath = 'foo/bar/image.jpg'; $variationName = 'my_variation'; @@ -159,27 +152,12 @@ public function testGetVariationNotStored() $imageHeight = 300; $expectedUrl = "http://localhost/foo/bar/image_$variationName.jpg"; - $this->ioResolver - ->expects(self::once()) - ->method('isStored') - ->with($originalPath, $variationName) - ->will(self::returnValue(false)); - - $this->logger - ->expects(self::once()) - ->method('debug'); - - $binary = $this->createMock(BinaryInterface::class); - $this->dataLoader - ->expects(self::once()) - ->method('find') - ->with($originalPath) - ->will(self::returnValue($binary)); + $binary = $this->configureMocksForNotStoredVariation($originalPath, $variationName); $this->filterManager ->expects(self::once()) ->method('applyFilter') ->with($binary, $variationName) - ->will(self::returnValue($binary)); + ->willReturn($binary); $this->ioResolver ->expects(self::once()) ->method('store') @@ -195,7 +173,10 @@ public function testGetVariationNotStored() ); } - public function testGetVariationOriginal() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationOriginal(): void { $originalPath = 'foo/bar/image.jpg'; $variationName = 'original'; @@ -212,16 +193,16 @@ public function testGetVariationOriginal() ] ); $field = new Field([ - 'value' => $imageValue, - 'fieldDefIdentifier' => 'image_field', - ]); + 'value' => $imageValue, + 'fieldDefIdentifier' => 'image_field', + ]); $expectedUrl = 'http://localhost/foo/bar/image.jpg'; $this->ioResolver ->expects(self::never()) ->method('isStored') ->with($originalPath, $variationName) - ->will(self::returnValue(false)); + ->willReturn(false); $this->logger ->expects(self::once()) @@ -231,7 +212,7 @@ public function testGetVariationOriginal() ->expects(self::once()) ->method('resolve') ->with($originalPath, $variationName) - ->will(self::returnValue($expectedUrl)); + ->willReturn($expectedUrl); $expected = new ImageVariation( [ @@ -244,15 +225,18 @@ public function testGetVariationOriginal() 'width' => $imageWidth, ] ); - self::assertEquals($expected, $this->decoratedAliasGenerator->getVariation($field, new VersionInfo(), $variationName)); + self::assertEquals( + $expected, + $this->decoratedAliasGenerator->getVariation($field, new VersionInfo(), $variationName) + ); } /** * Test obtaining Image Variation that hasn't been stored yet and has multiple references. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationNotStoredHavingReferences() + public function testGetVariationNotStoredHavingReferences(): void { $originalPath = 'foo/bar/image.jpg'; $variationName = 'my_variation'; @@ -269,39 +253,19 @@ public function testGetVariationNotStoredHavingReferences() $imageHeight = 300; $expectedUrl = "http://localhost/foo/bar/image_$variationName.jpg"; - $this->ioResolver - ->expects(self::once()) - ->method('isStored') - ->with($originalPath, $variationName) - ->will(self::returnValue(false)); - - $this->logger - ->expects(self::once()) - ->method('debug'); - - $binary = $this->createMock(BinaryInterface::class); - $this->dataLoader - ->expects(self::once()) - ->method('find') - ->with($originalPath) - ->will(self::returnValue($binary)); + $binary = $this->configureMocksForNotStoredVariation($originalPath, $variationName); // Filter manager is supposed to be called 3 times to generate references, and then passed variation. $this->filterManager - ->expects(self::at(0)) - ->method('applyFilter') - ->with($binary, $reference2) - ->will(self::returnValue($binary)); - $this->filterManager - ->expects(self::at(1)) - ->method('applyFilter') - ->with($binary, $reference1) - ->will(self::returnValue($binary)); - $this->filterManager - ->expects(self::at(2)) + ->expects(self::exactly(3)) ->method('applyFilter') - ->with($binary, $variationName) - ->will(self::returnValue($binary)); + ->willReturnMap( + [ + [$binary, $reference2, [], $binary], + [$binary, $reference1, [], $binary], + [$binary, $variationName, [], $binary], + ] + ); $this->ioResolver ->expects(self::once()) @@ -321,9 +285,9 @@ public function testGetVariationNotStoredHavingReferences() /** * Test obtaining Image Variation that has been stored already. * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationAlreadyStored() + public function testGetVariationAlreadyStored(): void { $originalPath = 'foo/bar/image.jpg'; $variationName = 'my_variation'; @@ -332,25 +296,7 @@ public function testGetVariationAlreadyStored() $imageHeight = 300; $expectedUrl = "http://localhost/foo/bar/image_$variationName.jpg"; - $this->ioResolver - ->expects(self::once()) - ->method('isStored') - ->with($originalPath, $variationName) - ->will(self::returnValue(true)); - - $this->logger - ->expects(self::once()) - ->method('debug'); - - $this->dataLoader - ->expects(self::never()) - ->method('find'); - $this->filterManager - ->expects(self::never()) - ->method('applyFilter'); - $this->ioResolver - ->expects(self::never()) - ->method('store'); + $this->configureMocksForAlreadyStoredVariation($originalPath, $variationName); $this->assertImageVariationIsCorrect( $expectedUrl, @@ -362,7 +308,10 @@ public function testGetVariationAlreadyStored() ); } - public function testGetVariationOriginalNotFound() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationOriginalNotFound(): void { $this->expectException(SourceImageNotFoundException::class); @@ -372,13 +321,16 @@ public function testGetVariationOriginalNotFound() ->will(self::throwException(new NotLoadableException())); $field = new Field([ - 'value' => new ImageValue(), - 'fieldDefIdentifier' => 'image_field', - ]); + 'value' => new ImageValue(), + 'fieldDefIdentifier' => 'image_field', + ]); $this->aliasGenerator->getVariation($field, new VersionInfo(), 'foo'); } - public function testGetVariationInvalidVariation() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationInvalidVariation(): void { $this->expectException(InvalidVariationException::class); @@ -388,25 +340,7 @@ public function testGetVariationInvalidVariation() $imageValue = new ImageValue(['id' => $originalPath, 'imageId' => $imageId]); $field = new Field(['value' => $imageValue, 'fieldDefIdentifier' => 'image_field']); - $this->ioResolver - ->expects(self::once()) - ->method('isStored') - ->with($originalPath, $variationName) - ->will(self::returnValue(true)); - - $this->logger - ->expects(self::once()) - ->method('debug'); - - $this->dataLoader - ->expects(self::never()) - ->method('find'); - $this->filterManager - ->expects(self::never()) - ->method('applyFilter'); - $this->ioResolver - ->expects(self::never()) - ->method('store'); + $this->configureMocksForAlreadyStoredVariation($originalPath, $variationName); $this->ioResolver ->expects(self::once()) @@ -422,6 +356,7 @@ public function testGetVariationInvalidVariation() * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ protected function assertImageVariationIsCorrect( string $expectedUrl, @@ -433,14 +368,14 @@ protected function assertImageVariationIsCorrect( ): void { $imageValue = new ImageValue(['id' => $originalPath, 'imageId' => $imageId]); $field = new Field([ - 'value' => $imageValue, - 'fieldDefIdentifier' => 'image_field', - ]); + 'value' => $imageValue, + 'fieldDefIdentifier' => 'image_field', + ]); $binaryFile = new BinaryFile( [ 'id' => 'foo/bar/image.jpg', - 'uri' => "_aliases/{$variationName}/foo/bar/image.jpg", + 'uri' => "_aliases/$variationName/foo/bar/image.jpg", 'mtime' => new DateTime('2020-01-01 00:00:00'), 'size' => 123, ] @@ -514,4 +449,51 @@ protected function assertImageVariationIsCorrect( $this->decoratedAliasGenerator->getVariation($field, new VersionInfo(), $variationName) ); } + + private function configureMocksForAlreadyStoredVariation(string $originalPath, string $variationName): void + { + $this->ioResolver + ->expects(self::once()) + ->method('isStored') + ->with($originalPath, $variationName) + ->willReturn(true); + + $this->logger + ->expects(self::once()) + ->method('debug'); + + $this->dataLoader + ->expects(self::never()) + ->method('find'); + $this->filterManager + ->expects(self::never()) + ->method('applyFilter'); + $this->ioResolver + ->expects(self::never()) + ->method('store'); + } + + private function configureMocksForNotStoredVariation( + string $originalPath, + string $variationName + ): BinaryInterface&MockObject { + $this->ioResolver + ->expects(self::once()) + ->method('isStored') + ->with($originalPath, $variationName) + ->willReturn(false); + + $this->logger + ->expects(self::once()) + ->method('debug'); + + $binary = $this->createMock(BinaryInterface::class); + $this->dataLoader + ->expects(self::once()) + ->method('find') + ->with($originalPath) + ->willReturn($binary); + + return $binary; + } } diff --git a/tests/bundle/Core/Imagine/BinaryLoaderTest.php b/tests/bundle/Core/Imagine/BinaryLoaderTest.php index feddb12766..0fdab5dc7c 100644 --- a/tests/bundle/Core/Imagine/BinaryLoaderTest.php +++ b/tests/bundle/Core/Imagine/BinaryLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -15,16 +16,18 @@ use Ibexa\Core\IO\Values\MissingBinaryFile; use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException; use Liip\ImagineBundle\Model\Binary; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\MimeTypes; -class BinaryLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\BinaryLoader + */ +final class BinaryLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $ioService; + private IOServiceInterface & MockObject $ioService; - /** @var \Ibexa\Bundle\Core\Imagine\BinaryLoader */ - private $binaryLoader; + private BinaryLoader $binaryLoader; protected function setUp(): void { @@ -33,10 +36,8 @@ protected function setUp(): void $this->binaryLoader = new BinaryLoader($this->ioService, new MimeTypes()); } - public function testFindNotFound() + public function testFindNotFound(): void { - $this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class); - $path = 'something.jpg'; $this->ioService ->expects(self::once()) @@ -44,24 +45,25 @@ public function testFindNotFound() ->with($path) ->will(self::throwException(new NotFoundException('foo', 'bar'))); + $this->expectException(NotLoadableException::class); $this->binaryLoader->find($path); } - public function testFindMissing() + public function testFindMissing(): void { - $this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class); + $this->expectException(NotLoadableException::class); $path = 'something.jpg'; $this->ioService ->expects(self::once()) ->method('loadBinaryFile') ->with($path) - ->will(self::returnValue(new MissingBinaryFile())); + ->willReturn(new MissingBinaryFile()); $this->binaryLoader->find($path); } - public function testFindBadPathRoot() + public function testFindBadPathRoot(): void { $path = 'var/site/storage/images/1/2/3/123-name/name.png'; $this->ioService diff --git a/tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php b/tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php index 0f53eea8d3..008b22e370 100644 --- a/tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php +++ b/tests/bundle/Core/Imagine/Cache/Resolver/ProxyResolverTest.php @@ -4,23 +4,25 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Cache\Resolver; use Ibexa\Bundle\Core\Imagine\Cache\Resolver\ProxyResolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ProxyResolverTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Cache\Resolver\ProxyResolver + */ +final class ProxyResolverTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $resolver; + private ResolverInterface & MockObject $resolver; - /** @var string */ - private $path; + private string $path; - /** @var string */ - private $filter; + private string $filter; protected function setUp(): void { @@ -30,57 +32,45 @@ protected function setUp(): void $this->filter = 'medium'; } - public function testResolveUsingProxyHostWithTrailingSlash() + /** + * @dataProvider getDataForTestResolve + * + * @param string[] $hosts + */ + public function testResolve(array $hosts, string $resolvedPath, string $expected): void { - $hosts = ['http://ezplatform.com/']; $proxyResolver = new ProxyResolver($this->resolver, $hosts); - $resolvedPath = 'http://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - $this->resolver ->expects(self::once()) ->method('resolve') ->with($this->path, $this->filter) ->willReturn($resolvedPath); - $expected = 'http://ezplatform.com/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - self::assertEquals($expected, $proxyResolver->resolve($this->path, $this->filter)); } - public function testResolveAndRemovePortUsingProxyHost() + /** + * @return iterable + */ + public static function getDataForTestResolve(): iterable { - $hosts = ['http://ibexa.co']; - $proxyResolver = new ProxyResolver($this->resolver, $hosts); - - $resolvedPath = 'http://ibexa.co:8060/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - - $this->resolver - ->expects(self::once()) - ->method('resolve') - ->with($this->path, $this->filter) - ->willReturn($resolvedPath); - - $expected = 'http://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - - self::assertEquals($expected, $proxyResolver->resolve($this->path, $this->filter)); - } - - public function testResolveAndRemovePortUsingProxyHostWithTrailingSlash() - { - $hosts = ['http://ibexa.co']; - $proxyResolver = new ProxyResolver($this->resolver, $hosts); - - $resolvedPath = 'http://ezplatform.com:8080/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - - $this->resolver - ->expects(self::once()) - ->method('resolve') - ->with($this->path, $this->filter) - ->willReturn($resolvedPath); - - $expected = 'http://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg'; - - self::assertEquals($expected, $proxyResolver->resolve($this->path, $this->filter)); + yield 'proxy host with trailing slash' => [ + ['https://qntmgroup.com/'], + 'https://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + 'https://qntmgroup.com/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + ]; + + yield 'remove port using proxy host' => [ + ['https://ibexa.co'], + 'https://ibexa.co:8060/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + 'https://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + ]; + + yield 'remove port using proxy host with trailing slash' => [ + ['https://ibexa.co'], + 'https://qntmgroup.com:8080/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + 'https://ibexa.co/var/site/storage/images/_aliases/medium/7/4/2/0/247-1-eng-GB/img_0885.jpg', + ]; } } diff --git a/tests/bundle/Core/Imagine/Cache/Resolver/RelativeResolverTest.php b/tests/bundle/Core/Imagine/Cache/Resolver/RelativeResolverTest.php index 1d41a4f323..4aead0c298 100644 --- a/tests/bundle/Core/Imagine/Cache/Resolver/RelativeResolverTest.php +++ b/tests/bundle/Core/Imagine/Cache/Resolver/RelativeResolverTest.php @@ -4,17 +4,21 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Cache\Resolver; use Ibexa\Bundle\Core\Imagine\Cache\Resolver\RelativeResolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class RelativeResolverTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Cache\Resolver\RelativeResolver + */ +final class RelativeResolverTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $liipResolver; + private ResolverInterface & MockObject $liipResolver; protected function setUp(): void { @@ -22,14 +26,14 @@ protected function setUp(): void $this->liipResolver = $this->getMockBuilder(ResolverInterface::class)->getMock(); } - public function testResolve() + public function testResolve(): void { $resolver = new RelativeResolver($this->liipResolver); $path = '7/4/2/0/247-1-eng-GB/test.png'; $filter = 'big'; - $absolute = 'http://ibexa.co/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png'; + $absolute = 'https://ibexa.co/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png'; $expected = '/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png'; $this->liipResolver diff --git a/tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php b/tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php index 32c17cf66c..b3125e4b12 100644 --- a/tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php +++ b/tests/bundle/Core/Imagine/Cache/ResolverFactoryTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Cache; @@ -12,18 +13,19 @@ use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver; use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ResolverFactoryTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Cache\ResolverFactory + */ +final class ResolverFactoryTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ - private $configResolver; + private ConfigResolverInterface&MockObject $configResolver; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface */ - private $resolver; + private ResolverInterface & MockObject $resolver; - /** @var \Ibexa\Bundle\Core\Imagine\Cache\ResolverFactory */ - private $factory; + private ResolverFactory $factory; protected function setUp(): void { @@ -38,18 +40,18 @@ protected function setUp(): void ); } - public function testCreateProxyCacheResolver() + public function testCreateProxyCacheResolver(): void { $this->configResolver - ->expects(self::at(0)) + ->expects(self::once()) ->method('hasParameter') ->with('image_host') ->willReturn(true); - $host = 'http://ibexa.co'; + $host = 'https://ibexa.co'; $this->configResolver - ->expects(self::at(1)) + ->expects(self::once()) ->method('getParameter') ->with('image_host') ->willReturn($host); @@ -59,10 +61,10 @@ public function testCreateProxyCacheResolver() self::assertEquals($expected, $this->factory->createCacheResolver()); } - public function testCreateRelativeCacheResolver() + public function testCreateRelativeCacheResolver(): void { $this->configResolver - ->expects(self::at(0)) + ->expects(self::once()) ->method('hasParameter') ->with('image_host') ->willReturn(true); @@ -70,7 +72,7 @@ public function testCreateRelativeCacheResolver() $host = '/'; $this->configResolver - ->expects(self::at(1)) + ->expects(self::once()) ->method('getParameter') ->with('image_host') ->willReturn($host); diff --git a/tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php b/tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php index 4f4ef7ca3f..57d1c3241d 100644 --- a/tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php +++ b/tests/bundle/Core/Imagine/Filter/AbstractFilterTest.php @@ -4,16 +4,17 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter; use Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class AbstractFilterTest extends TestCase { - /** @var \Ibexa\Bundle\Core\Imagine\Filter\AbstractFilter */ - protected $filter; + protected AbstractFilter & MockObject $filter; protected function setUp(): void { @@ -21,12 +22,12 @@ protected function setUp(): void $this->filter = $this->getFilter(); } - protected function getFilter() + protected function getFilter(): AbstractFilter & MockObject { return $this->getMockForAbstractClass(AbstractFilter::class); } - public function testGetSetOptions() + public function testGetSetOptions(): void { self::assertSame([], $this->filter->getOptions()); $options = ['foo' => 'bar', 'some' => ['thing']]; @@ -37,7 +38,7 @@ public function testGetSetOptions() /** * @dataProvider getSetOptionNoDefaulValueProvider */ - public function testGetSetOptionNoDefaultValue($optionName, $value) + public function testGetSetOptionNoDefaultValue(string $optionName, mixed $value): void { self::assertFalse($this->filter->hasOption($optionName)); self::assertNull($this->filter->getOption($optionName)); @@ -46,7 +47,10 @@ public function testGetSetOptionNoDefaultValue($optionName, $value) self::assertSame($value, $this->filter->getOption($optionName)); } - public function getSetOptionNoDefaulValueProvider() + /** + * @return array + */ + public static function getSetOptionNoDefaulValueProvider(): array { return [ ['foo', 'bar'], @@ -61,7 +65,7 @@ public function getSetOptionNoDefaulValueProvider() /** * @dataProvider getSetOptionWithDefaulValueProvider */ - public function testGetSetOptionWithDefaultValue($optionName, $value, $defaultValue) + public function testGetSetOptionWithDefaultValue(string $optionName, mixed $value, mixed $defaultValue): void { self::assertFalse($this->filter->hasOption($optionName)); self::assertSame($defaultValue, $this->filter->getOption($optionName, $defaultValue)); @@ -70,7 +74,10 @@ public function testGetSetOptionWithDefaultValue($optionName, $value, $defaultVa self::assertSame($value, $this->filter->getOption($optionName)); } - public function getSetOptionWithDefaulValueProvider() + /** + * @return array + */ + public static function getSetOptionWithDefaulValueProvider(): array { return [ ['foo', 'bar', 'default'], diff --git a/tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php b/tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php index fe9cf8af97..d9bffece15 100644 --- a/tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php +++ b/tests/bundle/Core/Imagine/Filter/FilterConfigurationTest.php @@ -4,20 +4,24 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter; use Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use RuntimeException; -class FilterConfigurationTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration + */ +final class FilterConfigurationTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $configResolver; + private ConfigResolverInterface & MockObject $configResolver; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration */ - private $filterConfiguration; + private FilterConfiguration $filterConfiguration; protected function setUp(): void { @@ -27,7 +31,7 @@ protected function setUp(): void $this->filterConfiguration->setConfigResolver($this->configResolver); } - public function testGetOnlyImagineFilters() + public function testGetOnlyImagineFilters(): void { $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; @@ -38,16 +42,14 @@ public function testGetOnlyImagineFilters() ->expects(self::exactly(2)) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue([])); + ->willReturn([]); self::assertSame($fooConfig, $this->filterConfiguration->get('foo')); self::assertSame($barConfig, $this->filterConfiguration->get('bar')); } - public function testGetNoEzVariationInvalidImagineFilter() + public function testGetNoVariationInvalidImagineFilter(): void { - $this->expectException(\RuntimeException::class); - $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; $this->filterConfiguration->set('foo', $fooConfig); @@ -57,12 +59,14 @@ public function testGetNoEzVariationInvalidImagineFilter() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue([])); + ->willReturn([]); + + $this->expectException(RuntimeException::class); $this->filterConfiguration->get('foobar'); } - public function testGetWithEzVariationNullConfiguration(): void + public function testGetWithVariationNullConfiguration(): void { $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; @@ -76,7 +80,7 @@ public function testGetWithEzVariationNullConfiguration(): void ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertSame( [ @@ -90,7 +94,7 @@ public function testGetWithEzVariationNullConfiguration(): void ); } - public function testGetEzVariationNoReference() + public function testGetVariationNoReference(): void { $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; @@ -105,7 +109,7 @@ public function testGetEzVariationNoReference() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertSame( [ @@ -119,7 +123,7 @@ public function testGetEzVariationNoReference() ); } - public function testGetEzVariationWithReference() + public function testGetVariationWithReference(): void { $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; @@ -135,7 +139,7 @@ public function testGetEzVariationWithReference() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertSame( [ @@ -149,7 +153,7 @@ public function testGetEzVariationWithReference() ); } - public function testGetEzVariationImagineFilters() + public function testGetVariationImagineFilters(): void { $filters = ['some_filter' => []]; $imagineConfig = ['filters' => $filters]; @@ -163,7 +167,7 @@ public function testGetEzVariationImagineFilters() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertSame( [ @@ -177,7 +181,7 @@ public function testGetEzVariationImagineFilters() ); } - public function testGetEzVariationImagineOptions() + public function testGetVariationImagineOptions(): void { $imagineConfig = [ 'foo_option' => 'foo', @@ -194,7 +198,7 @@ public function testGetEzVariationImagineOptions() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertSame( [ @@ -210,7 +214,7 @@ public function testGetEzVariationImagineOptions() ); } - public function testAll() + public function testAll(): void { $fooConfig = ['fooconfig']; $barConfig = ['barconfig']; @@ -226,7 +230,7 @@ public function testAll() ->expects(self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue($variations)); + ->willReturn($variations); self::assertEquals( [ diff --git a/tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php index 3dc1640763..3bfbbc40c7 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/BorderFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -16,20 +17,28 @@ use Imagine\Image\Palette\PaletteInterface; use PHPUnit\Framework\TestCase; -class BorderFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\BorderFilterLoader + */ +final class BorderFilterLoaderTest extends TestCase { /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { - $this->expectException(InvalidArgumentException::class); - $loader = new BorderFilterLoader(); + + $this->expectException(InvalidArgumentException::class); $loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -38,7 +47,7 @@ public function loadInvalidProvider() ]; } - public function testLoadDefaultColor() + public function testLoadDefaultColor(): void { $image = $this->createMock(ImageInterface::class); $options = [10, 10]; @@ -47,36 +56,36 @@ public function testLoadDefaultColor() $image ->expects(self::once()) ->method('palette') - ->will(self::returnValue($palette)); + ->willReturn($palette); $palette ->expects(self::once()) ->method('color') ->with(BorderFilterLoader::DEFAULT_BORDER_COLOR) - ->will(self::returnValue($this->createMock(ColorInterface::class))); + ->willReturn($this->createMock(ColorInterface::class)); $box = $this->createMock(BoxInterface::class); $image ->expects(self::once()) ->method('getSize') - ->will(self::returnValue($box)); + ->willReturn($box); $box - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('getWidth') - ->will(self::returnValue(100)); + ->willReturn(100); $box ->expects(self::any()) ->method('getHeight') - ->will(self::returnValue(100)); + ->willReturn(100); $drawer = $this->createMock(DrawerInterface::class); $image ->expects(self::once()) ->method('draw') - ->will(self::returnValue($drawer)); + ->willReturn($drawer); $drawer - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('line') - ->will(self::returnValue($drawer)); + ->willReturn($drawer); $loader = new BorderFilterLoader(); self::assertSame($image, $loader->load($image, $options)); @@ -85,7 +94,7 @@ public function testLoadDefaultColor() /** * @dataProvider loadProvider */ - public function testLoad($thickX, $thickY, $color) + public function testLoad(int $thickX, int $thickY, string $color): void { $image = $this->createMock(ImageInterface::class); $options = [$thickX, $thickY, $color]; @@ -94,42 +103,45 @@ public function testLoad($thickX, $thickY, $color) $image ->expects(self::once()) ->method('palette') - ->will(self::returnValue($palette)); + ->willReturn($palette); $palette ->expects(self::once()) ->method('color') ->with($color) - ->will(self::returnValue($this->createMock(ColorInterface::class))); + ->willReturn($this->createMock(ColorInterface::class)); $box = $this->createMock(BoxInterface::class); $image ->expects(self::once()) ->method('getSize') - ->will(self::returnValue($box)); + ->willReturn($box); $box - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('getWidth') - ->will(self::returnValue(1000)); + ->willReturn(1000); $box - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('getHeight') - ->will(self::returnValue(1000)); + ->willReturn(1000); $drawer = $this->createMock(DrawerInterface::class); $image ->expects(self::once()) ->method('draw') - ->will(self::returnValue($drawer)); + ->willReturn($drawer); $drawer - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('line') - ->will(self::returnValue($drawer)); + ->willReturn($drawer); $loader = new BorderFilterLoader(); self::assertSame($image, $loader->load($image, $options)); } - public function loadProvider() + /** + * @return array + */ + public static function loadProvider(): array { return [ [10, 10, '#fff'], diff --git a/tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php index e937182c95..220a16c61e 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/CropFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class CropFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\CropFilterLoader + */ +final class CropFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\CropFilterLoader */ - private $loader; + private CropFilterLoader $loader; protected function setUp(): void { @@ -31,15 +34,20 @@ protected function setUp(): void /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -50,7 +58,7 @@ public function loadInvalidProvider() ]; } - public function testLoad() + public function testLoad(): void { $width = 123; $height = 789; @@ -62,7 +70,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, ['size' => [$width, $height], 'start' => [$offsetX, $offsetY]]) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$width, $height, $offsetX, $offsetY])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php index eaa18287ba..e64e8e0292 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -12,20 +13,23 @@ use Imagine\Image\ImageInterface; use PHPUnit\Framework\TestCase; -class GrayscaleFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\GrayscaleFilterLoader + */ +final class GrayscaleFilterLoaderTest extends TestCase { - public function testLoad() + public function testLoad(): void { $image = $this->createMock(ImageInterface::class); $effects = $this->createMock(EffectsInterface::class); $image ->expects(self::once()) ->method('effects') - ->will(self::returnValue($effects)); + ->willReturn($effects); $effects ->expects(self::once()) ->method('grayscale') - ->will(self::returnValue($effects)); + ->willReturn($effects); $loader = new GrayscaleFilterLoader(); self::assertSame($image, $loader->load($image)); diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoaderTest.php index b4a6eb2942..3a71c78a14 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ReduceNoiseFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -13,22 +14,20 @@ use Imagine\Image\ImageInterface; use PHPUnit\Framework\TestCase; -class ReduceNoiseFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ReduceNoiseFilterLoader + */ +final class ReduceNoiseFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $filter; - - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ReduceNoiseFilterLoader */ - private $loader; + private ReduceNoiseFilterLoader $loader; protected function setUp(): void { - parent::setUp(); - $this->filter = $this->createMock(FilterInterface::class); - $this->loader = new ReduceNoiseFilterLoader($this->filter); + $filter = $this->createMock(FilterInterface::class); + $this->loader = new ReduceNoiseFilterLoader($filter); } - public function testLoadInvalidDriver() + public function testLoadInvalidDriver(): void { $this->expectException(NotSupportedException::class); diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php index c120b142ab..4329041df7 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleDownOnlyFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleDownOnlyFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleDownOnlyFilterLoader + */ +final class ScaleDownOnlyFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleDownOnlyFilterLoader */ - private $loader; + private ScaleDownOnlyFilterLoader $loader; protected function setUp(): void { @@ -31,15 +34,20 @@ protected function setUp(): void /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -48,7 +56,7 @@ public function loadInvalidProvider() ]; } - public function testLoad() + public function testLoad(): void { $options = [123, 456]; $image = $this->createMock(ImageInterface::class); @@ -56,7 +64,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['size' => $options, 'mode' => 'inset'])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, $options)); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php index 273b6dd972..369cf0ae65 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleExactFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleExactFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleExactFilterLoader + */ +final class ScaleExactFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleExactFilterLoader */ - private $loader; + private ScaleExactFilterLoader $loader; protected function setUp(): void { @@ -31,15 +34,20 @@ protected function setUp(): void /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -48,7 +56,7 @@ public function loadInvalidProvider() ]; } - public function testLoad() + public function testLoad(): void { $options = [123, 456]; $image = $this->createMock(ImageInterface::class); @@ -56,7 +64,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, ['size' => $options]) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, $options)); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php index 873eb0d0fc..22c85587f3 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -12,15 +13,17 @@ use Imagine\Image\Box; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleFilterLoader + */ +final class ScaleFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleFilterLoader */ - private $loader; + private ScaleFilterLoader $loader; protected function setUp(): void { @@ -32,15 +35,20 @@ protected function setUp(): void /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -49,7 +57,7 @@ public function loadInvalidProvider() ]; } - public function testLoadHeighten() + public function testLoadHeighten(): void { $width = 900; $height = 400; @@ -61,18 +69,18 @@ public function testLoadHeighten() $image ->expects(self::once()) ->method('getSize') - ->will(self::returnValue($box)); + ->willReturn($box); $this->innerLoader ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['heighten' => $height])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$width, $height])); } - public function testLoadWiden() + public function testLoadWiden(): void { $width = 900; $height = 600; @@ -84,13 +92,13 @@ public function testLoadWiden() $image ->expects(self::once()) ->method('getSize') - ->will(self::returnValue($box)); + ->willReturn($box); $this->innerLoader ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['widen' => $width])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$width, $height])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php index 840cca4006..0fec8b000d 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightDownOnlyFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleHeightDownOnlyFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleHeightDownOnlyFilterLoader + */ +final class ScaleHeightDownOnlyFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleHeightDownOnlyFilterLoader */ - private $loader; + private ScaleHeightDownOnlyFilterLoader $loader; protected function setUp(): void { @@ -29,14 +32,14 @@ protected function setUp(): void $this->loader->setInnerLoader($this->innerLoader); } - public function testLoadInvalid() + public function testLoadInvalid(): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), []); } - public function testLoad() + public function testLoad(): void { $height = 123; $image = $this->createMock(ImageInterface::class); @@ -44,7 +47,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['size' => [null, $height], 'mode' => 'inset'])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$height])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php index 9b36149c03..f4ffcbcb73 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleHeightFilterLoaderTest.php @@ -11,15 +11,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleHeightFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleHeightFilterLoader + */ +final class ScaleHeightFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleHeightFilterLoader */ - private $loader; + private ScaleHeightFilterLoader $loader; protected function setUp(): void { @@ -29,14 +31,14 @@ protected function setUp(): void $this->loader->setInnerLoader($this->innerLoader); } - public function testLoadFail() + public function testLoadFail(): void { $this->expectException(InvalidArgumentException::class); - $this->loader->load($this->createMock(ImageInterface::class, [])); + $this->loader->load($this->createMock(ImageInterface::class)); } - public function testLoad() + public function testLoad(): void { $height = 123; $image = $this->createMock(ImageInterface::class); @@ -44,7 +46,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['heighten' => $height])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$height])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php index 762ec807e8..c5ec9b177d 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScalePercentFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -12,15 +13,17 @@ use Imagine\Image\Box; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScalePercentFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScalePercentFilterLoader + */ +final class ScalePercentFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScalePercentFilterLoader */ - private $loader; + private ScalePercentFilterLoader $loader; protected function setUp(): void { @@ -32,15 +35,20 @@ protected function setUp(): void /** * @dataProvider loadInvalidProvider + * + * @param array $options */ - public function testLoadInvalidOptions(array $options) + public function testLoadInvalidOptions(array $options): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), $options); } - public function loadInvalidProvider() + /** + * @return array}> + */ + public static function loadInvalidProvider(): array { return [ [[]], @@ -49,7 +57,7 @@ public function loadInvalidProvider() ]; } - public function testLoad() + public function testLoad(): void { $widthPercent = 40; $heightPercent = 125; @@ -63,13 +71,13 @@ public function testLoad() $image ->expects(self::once()) ->method('getSize') - ->will(self::returnValue($box)); + ->willReturn($box); $this->innerLoader ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['size' => [$expectedWidth, $expectedHeight]])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$widthPercent, $heightPercent])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php index 4ad49d493d..dbe207eaa8 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthDownOnlyFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleWidthDownOnlyFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleWidthDownOnlyFilterLoader + */ +final class ScaleWidthDownOnlyFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleWidthDownOnlyFilterLoader */ - private $loader; + private ScaleWidthDownOnlyFilterLoader $loader; protected function setUp(): void { @@ -29,14 +32,14 @@ protected function setUp(): void $this->loader->setInnerLoader($this->innerLoader); } - public function testLoadInvalid() + public function testLoadInvalid(): void { $this->expectException(InvalidArgumentException::class); $this->loader->load($this->createMock(ImageInterface::class), []); } - public function testLoad() + public function testLoad(): void { $width = 123; $image = $this->createMock(ImageInterface::class); @@ -44,7 +47,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['size' => [$width, null], 'mode' => 'inset'])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$width])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php index 78fb82b9e0..6132642764 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/ScaleWidthFilterLoaderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; @@ -11,15 +12,17 @@ use Imagine\Exception\InvalidArgumentException; use Imagine\Image\ImageInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ScaleWidthFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleWidthFilterLoader + */ +final class ScaleWidthFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $innerLoader; + private LoaderInterface & MockObject $innerLoader; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\ScaleWidthFilterLoader */ - private $loader; + private ScaleWidthFilterLoader $loader; protected function setUp(): void { @@ -29,14 +32,14 @@ protected function setUp(): void $this->loader->setInnerLoader($this->innerLoader); } - public function testLoadFail() + public function testLoadFail(): void { $this->expectException(InvalidArgumentException::class); - $this->loader->load($this->createMock(ImageInterface::class, [])); + $this->loader->load($this->createMock(ImageInterface::class)); } - public function testLoad() + public function testLoad(): void { $width = 123; $image = $this->createMock(ImageInterface::class); @@ -44,7 +47,7 @@ public function testLoad() ->expects(self::once()) ->method('load') ->with($image, self::equalTo(['widen' => $width])) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$width])); } diff --git a/tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php b/tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php index 4af693b48b..1881baad01 100644 --- a/tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php +++ b/tests/bundle/Core/Imagine/Filter/Loader/SwirlFilterLoaderTest.php @@ -4,21 +4,24 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter\Loader; use Ibexa\Bundle\Core\Imagine\Filter\FilterInterface; use Ibexa\Bundle\Core\Imagine\Filter\Loader\SwirlFilterLoader; use Imagine\Image\ImageInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class SwirlFilterLoaderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\Loader\SwirlFilterLoader + */ +final class SwirlFilterLoaderTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $filter; + private FilterInterface & MockObject $filter; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\Loader\SwirlFilterLoader */ - private $loader; + private SwirlFilterLoader $loader; protected function setUp(): void { @@ -27,7 +30,7 @@ protected function setUp(): void $this->loader = new SwirlFilterLoader($this->filter); } - public function testLoadNoOption() + public function testLoadNoOption(): void { $image = $this->createMock(ImageInterface::class); $this->filter @@ -38,7 +41,7 @@ public function testLoadNoOption() ->expects(self::once()) ->method('apply') ->with($image) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image)); } @@ -46,7 +49,7 @@ public function testLoadNoOption() /** * @dataProvider loadWithOptionProvider */ - public function testLoadWithOption($degrees) + public function testLoadWithOption(float $degrees): void { $image = $this->createMock(ImageInterface::class); $this->filter @@ -58,12 +61,15 @@ public function testLoadWithOption($degrees) ->expects(self::once()) ->method('apply') ->with($image) - ->will(self::returnValue($image)); + ->willReturn($image); self::assertSame($image, $this->loader->load($image, [$degrees])); } - public function loadWithOptionProvider() + /** + * @return array + */ + public static function loadWithOptionProvider(): array { return [ [10], diff --git a/tests/bundle/Core/Imagine/Filter/UnsupportedFilterTest.php b/tests/bundle/Core/Imagine/Filter/UnsupportedFilterTest.php index 6076a2a83b..e4955a067b 100644 --- a/tests/bundle/Core/Imagine/Filter/UnsupportedFilterTest.php +++ b/tests/bundle/Core/Imagine/Filter/UnsupportedFilterTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\Filter; @@ -11,13 +12,16 @@ use Imagine\Exception\NotSupportedException; use Imagine\Image\ImageInterface; -class UnsupportedFilterTest extends AbstractFilterTest +/** + * @covers \Ibexa\Bundle\Core\Imagine\Filter\UnsupportedFilter + */ +final class UnsupportedFilterTest extends AbstractFilterTest { - public function testLoad() + public function testLoad(): void { - $this->expectException(NotSupportedException::class); - $filter = new UnsupportedFilter(); + + $this->expectException(NotSupportedException::class); $filter->apply($this->createMock(ImageInterface::class)); } } diff --git a/tests/bundle/Core/Imagine/IORepositoryResolverTest.php b/tests/bundle/Core/Imagine/IORepositoryResolverTest.php index f21e10559f..61500f4de5 100644 --- a/tests/bundle/Core/Imagine/IORepositoryResolverTest.php +++ b/tests/bundle/Core/Imagine/IORepositoryResolverTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -19,32 +20,27 @@ use Ibexa\Core\IO\Values\MissingBinaryFile; use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException; use Liip\ImagineBundle\Model\Binary; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RequestContext; -class IORepositoryResolverTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\IORepositoryResolver + */ +final class IORepositoryResolverTest extends TestCase { - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $ioService; - - /** @var \Symfony\Component\Routing\RequestContext */ - private $requestContext; + private IOServiceInterface & MockObject $ioService; - /** @var \PHPUnit\Framework\MockObject\MockObject */ - private $configResolver; + private RequestContext $requestContext; - /** @var \Ibexa\Bundle\Core\Imagine\IORepositoryResolver */ - private $imageResolver; + private ConfigResolverInterface & MockObject $configResolver; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration */ - private $filterConfiguration; + private IORepositoryResolver $imageResolver; - /** @var \Ibexa\Contracts\Core\Variation\VariationPurger|\PHPUnit\Framework\MockObject\MockObject */ - protected $variationPurger; + protected VariationPurger & MockObject $variationPurger; - /** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator|\PHPUnit\Framework\MockObject\MockObject */ - protected $variationPathGenerator; + protected VariationPathGenerator & MockObject $variationPathGenerator; protected function setUp(): void { @@ -52,14 +48,14 @@ protected function setUp(): void $this->ioService = $this->createMock(IOServiceInterface::class); $this->requestContext = new RequestContext(); $this->configResolver = $this->createMock(ConfigResolverInterface::class); - $this->filterConfiguration = new FilterConfiguration(); - $this->filterConfiguration->setConfigResolver($this->configResolver); + $filterConfiguration = new FilterConfiguration(); + $filterConfiguration->setConfigResolver($this->configResolver); $this->variationPurger = $this->createMock(VariationPurger::class); $this->variationPathGenerator = $this->createMock(VariationPathGenerator::class); $this->imageResolver = new IORepositoryResolver( $this->ioService, $this->requestContext, - $this->filterConfiguration, + $filterConfiguration, $this->variationPurger, $this->variationPathGenerator ); @@ -107,7 +103,7 @@ public function testIsStoredImageExists(): void ->expects(self::once()) ->method('exists') ->with($aliasPath) - ->will(self::returnValue(true)); + ->willReturn(true); self::assertTrue($this->imageResolver->isStored($path, $filter)); } @@ -128,7 +124,7 @@ public function testIsStoredImageDoesntExist(): void ->expects(self::once()) ->method('exists') ->with($aliasPath) - ->will(self::returnValue(false)); + ->willReturn(false); self::assertFalse($this->imageResolver->isStored($path, $filter)); } @@ -143,12 +139,12 @@ public function testResolve(string $path, string $filter, string $variationPath, } $this->ioService - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('loadBinaryFile') - ->will(self::returnValue(new BinaryFile(['uri' => $variationPath]))); + ->willReturn(new BinaryFile(['uri' => $variationPath])); $this->variationPathGenerator - ->expects(self::any()) + ->expects($filter !== IORepositoryResolver::VARIATION_ORIGINAL ? self::once() : self::never()) ->method('getVariationPath') ->willReturn($variationPath); @@ -165,7 +161,7 @@ public function testResolveMissing(): void ->expects(self::once()) ->method('loadBinaryFile') ->with($path) - ->will(self::returnValue(new MissingBinaryFile())); + ->willReturn(new MissingBinaryFile()); $this->imageResolver->resolve($path, 'some_filter'); } @@ -179,7 +175,7 @@ public function testResolveNotFound(): void ->expects(self::once()) ->method('loadBinaryFile') ->with($path) - ->will(self::throwException(new NotFoundException('foo', 'bar'))); + ->willThrowException(new NotFoundException('foo', 'bar')); $this->imageResolver->resolve($path, 'some_filter'); } @@ -246,14 +242,13 @@ public function testStore(): void { $filter = 'thumbnail'; $path = 'Tardis/bigger/in-the-inside/RiverSong.jpg'; - $aliasPath = 'Tardis/bigger/in-the-inside/RiverSong_thumbnail.jpg'; $binary = new Binary('foo content', 'some/mime-type'); $createStruct = new BinaryFileCreateStruct(); $this->ioService ->expects(self::once()) ->method('newBinaryCreateStructFromLocalFile') - ->will(self::returnValue($createStruct)); + ->willReturn($createStruct); $this->ioService ->expects(self::once()) @@ -262,95 +257,67 @@ public function testStore(): void $this->imageResolver->store($binary, $path, $filter); } - public function testRemoveEmptyFilters(): void + /** + * @return iterable}> + */ + public function getDataForTestRemove(): iterable { - $originalPath = 'foo/bar/test.jpg'; - $filters = ['filter1' => true, 'filter2' => true, 'chaud_cacao' => true]; - - $this->configResolver - ->expects(self::once()) - ->method('getParameter') - ->with('image_variations') - ->will(self::returnValue($filters)); - - $this->variationPathGenerator - ->expects(self::exactly(count($filters))) - ->method('getVariationPath') - ->will( - self::returnValueMap( - [ - ['foo/bar/test.jpg', 'filter1', 'foo/bar/test_filter1.jpg '], - ['foo/bar/test.jpg', 'filter2', 'foo/bar/test_filter2.jpg '], - ['foo/bar/test.jpg', 'chaud_cacao', 'foo/bar/test_chaud_cacao.jpg'], - ] - ) - ); - - $fileToDelete = 'foo/bar/test_chaud_cacao.jpg'; - $this->ioService - ->expects(self::exactly(count($filters))) - ->method('exists') - ->will( - self::returnValueMap( - [ - ['foo/bar/test_filter1.jpg', false], - ['foo/bar/test_filter2.jpg', false], - [$fileToDelete, true], - ] - ) - ); - - $binaryFile = new BinaryFile(['id' => $fileToDelete]); - $this->ioService - ->expects(self::once()) - ->method('loadBinaryFile') - ->with($fileToDelete) - ->will(self::returnValue($binaryFile)); - - $this->ioService - ->expects(self::once()) - ->method('deleteBinaryFile') - ->with($binaryFile); + yield 'empty filters' => [ + [], + ['filter1' => true, 'filter2' => true, 'chaud_cacao' => true], + ]; - $this->imageResolver->remove([$originalPath], []); + yield 'with filters' => [ + ['filter1', 'filter2', 'chaud_cacao'], + [], + ]; } - public function testRemoveWithFilters(): void + /** + * @dataProvider getDataForTestRemove + * + * @param string[] $filters + * @param array $imageVariations + */ + public function testRemove(array $filters, array $imageVariations): void { $originalPath = 'foo/bar/test.jpg'; - $filters = ['filter1', 'filter2', 'chaud_cacao']; $this->configResolver - ->expects(self::never()) + ->expects(!empty($filters) ? self::never() : self::once()) ->method('getParameter') ->with('image_variations') - ->will(self::returnValue([])); + ->willReturn($imageVariations); + $pathCount = !empty($filters) ? count($filters) : count($imageVariations); $this->variationPathGenerator - ->expects(self::exactly(count($filters))) + ->expects(self::exactly($pathCount)) ->method('getVariationPath') - ->will( - self::returnValueMap( - [ - ['foo/bar/test.jpg', 'filter1', 'foo/bar/test_filter1.jpg '], - ['foo/bar/test.jpg', 'filter2', 'foo/bar/test_filter2.jpg '], - ['foo/bar/test.jpg', 'chaud_cacao', 'foo/bar/test_chaud_cacao.jpg'], - ] - ) + ->willReturnMap( + [ + ['foo/bar/test.jpg', 'filter1', 'foo/bar/test_filter1.jpg'], + ['foo/bar/test.jpg', 'filter2', 'foo/bar/test_filter2.jpg'], + ['foo/bar/test.jpg', 'chaud_cacao', 'foo/bar/test_chaud_cacao.jpg'], + ] ); + $this->configureIoServiceForDeletingBinaryFile($pathCount); + + $this->imageResolver->remove([$originalPath], $filters); + } + + private function configureIoServiceForDeletingBinaryFile(int $pathCount): void + { $fileToDelete = 'foo/bar/test_chaud_cacao.jpg'; $this->ioService - ->expects(self::exactly(count($filters))) + ->expects(self::exactly($pathCount)) ->method('exists') - ->will( - self::returnValueMap( - [ - ['foo/bar/test_filter1.jpg', false], - ['foo/bar/test_filter2.jpg', false], - [$fileToDelete, true], - ] - ) + ->willReturnMap( + [ + ['foo/bar/test_filter1.jpg', false], + ['foo/bar/test_filter2.jpg', false], + [$fileToDelete, true], + ] ); $binaryFile = new BinaryFile(['id' => $fileToDelete]); @@ -358,13 +325,11 @@ public function testRemoveWithFilters(): void ->expects(self::once()) ->method('loadBinaryFile') ->with($fileToDelete) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); $this->ioService ->expects(self::once()) ->method('deleteBinaryFile') ->with($binaryFile); - - $this->imageResolver->remove([$originalPath], $filters); } } diff --git a/tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php b/tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php index dac3ff147d..386f674a87 100644 --- a/tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php +++ b/tests/bundle/Core/Imagine/ImageAsset/AliasGeneratorTest.php @@ -15,29 +15,30 @@ use Ibexa\Contracts\Core\Variation\VariationHandler; use Ibexa\Core\FieldType\Image; use Ibexa\Core\FieldType\ImageAsset; +use Ibexa\Core\FieldType\ImageAsset\AssetMapper; use Ibexa\Core\Repository\Values\Content\Content; use Ibexa\Core\Repository\Values\Content\VersionInfo; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class AliasGeneratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\ImageAsset\AliasGenerator + */ +final class AliasGeneratorTest extends TestCase { - /** @var \Ibexa\Bundle\Core\Imagine\ImageAsset\AliasGenerator */ - private $aliasGenerator; + private AliasGenerator $aliasGenerator; - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler|\PHPUnit\Framework\MockObject\MockObject */ - private $innerAliasGenerator; + private VariationHandler & MockObject $innerAliasGenerator; - /** @var \Ibexa\Contracts\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject */ - private $contentService; + private ContentService & MockObject $contentService; - /** @var \Ibexa\Core\FieldType\ImageAsset\AssetMapper|\PHPUnit\Framework\MockObject\MockObject */ - private $assetMapper; + private AssetMapper & MockObject $assetMapper; protected function setUp(): void { $this->innerAliasGenerator = $this->createMock(VariationHandler::class); $this->contentService = $this->createMock(ContentService::class); - $this->assetMapper = $this->createMock(ImageAsset\AssetMapper::class); + $this->assetMapper = $this->createMock(AssetMapper::class); $this->aliasGenerator = new AliasGenerator( $this->innerAliasGenerator, @@ -46,7 +47,10 @@ protected function setUp(): void ); } - public function testGetVariationOfImageAsset() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationOfImageAsset(): void { $assetField = new Field([ 'value' => new ImageAsset\Value(486), @@ -96,7 +100,7 @@ public function testGetVariationOfImageAsset() self::assertEquals($expectedVariation, $actualVariation); } - public function testGetVariationOfNonImageAsset() + public function testGetVariationOfNonImageAsset(): void { $imageField = new Field([ 'value' => new Image\Value([ @@ -134,7 +138,7 @@ public function testGetVariationOfNonImageAsset() self::assertEquals($expectedVariation, $actualVariation); } - public function testSupport() + public function testSupport(): void { self::assertTrue($this->aliasGenerator->supportsValue(new ImageAsset\Value())); self::assertFalse($this->aliasGenerator->supportsValue(new Image\Value())); diff --git a/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorConfiguratorTest.php b/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorConfiguratorTest.php index d1e84f2a66..8d75f26a3d 100644 --- a/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorConfiguratorTest.php +++ b/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorConfiguratorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -14,17 +15,20 @@ use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use PHPUnit\Framework\TestCase; -class PlaceholderAliasGeneratorConfiguratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\PlaceholderAliasGeneratorConfigurator + */ +final class PlaceholderAliasGeneratorConfiguratorTest extends TestCase { - public const BINARY_HANDLER_NAME = 'default'; - public const PROVIDER_TYPE = 'generic'; - public const PROVIDER_OPTIONS = [ + public const string BINARY_HANDLER_NAME = 'default'; + public const string PROVIDER_TYPE = 'generic'; + public const array PROVIDER_OPTIONS = [ 'a' => 'A', 'b' => 'B', 'c' => 'C', ]; - public function testConfigure() + public function testConfigure(): void { $configResolver = $this->createMock(ConfigResolverInterface::class); $configResolver diff --git a/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php b/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php index 92a097e089..564ad7b2c2 100644 --- a/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php +++ b/tests/bundle/Core/Imagine/PlaceholderAliasGeneratorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -23,28 +24,28 @@ use Ibexa\Core\IO\Values\BinaryFile; use Ibexa\Core\IO\Values\BinaryFileCreateStruct; use Ibexa\Core\Repository\Values\Content\VersionInfo; +use InvalidArgumentException; use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class PlaceholderAliasGeneratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\PlaceholderAliasGenerator + */ +final class PlaceholderAliasGeneratorTest extends TestCase { - /** @var \Ibexa\Bundle\Core\Imagine\PlaceholderAliasGenerator */ - private $aliasGenerator; + private PlaceholderAliasGenerator $aliasGenerator; - /** @var \Ibexa\Contracts\Core\Variation\VariationHandler|\PHPUnit\Framework\MockObject\MockObject */ - private $innerAliasGenerator; + private VariationHandler & MockObject $innerAliasGenerator; - /** @var \Ibexa\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $ioService; + private IOServiceInterface & MockObject $ioService; - /** @var \Ibexa\Bundle\Core\Imagine\IORepositoryResolver|\PHPUnit\Framework\MockObject\MockObject */ - private $ioResolver; + private IORepositoryResolver & MockObject $ioResolver; - /** @var \Ibexa\Bundle\Core\Imagine\PlaceholderProvider|\PHPUnit\Framework\MockObject\MockObject */ - private $placeholderProvider; + private PlaceholderProvider & MockObject $placeholderProvider; - /** @var array */ - private $placeholderOptions; + /** @var array */ + private array $placeholderOptions; protected function setUp(): void { @@ -64,14 +65,19 @@ protected function setUp(): void ); } - public function testGetVariationWrongValue() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetVariationWrongValue(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); - $field = new Field([ - 'value' => $this->createMock(FieldTypeValue::class), - 'fieldDefIdentifier' => 'image', - ]); + $field = new Field( + [ + 'value' => $this->createMock(FieldTypeValue::class), + 'fieldDefIdentifier' => 'image', + ] + ); $this->aliasGenerator->setPlaceholderProvider( $this->placeholderProvider, @@ -82,9 +88,17 @@ public function testGetVariationWrongValue() /** * @dataProvider getVariationProvider + * + * @param array $parameters + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationSkipsPlaceholderGeneration(Field $field, APIVersionInfo $versionInfo, string $variationName, array $parameters) - { + public function testGetVariationSkipsPlaceholderGeneration( + Field $field, + APIVersionInfo $versionInfo, + string $variationName, + array $parameters + ): void { $expectedVariation = $this->createMock(ImageVariation::class); $this->ioResolver @@ -115,9 +129,17 @@ public function testGetVariationSkipsPlaceholderGeneration(Field $field, APIVers /** * @dataProvider getVariationProvider + * + * @param array $parameters + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationOriginalFound(Field $field, APIVersionInfo $versionInfo, string $variationName, array $parameters) - { + public function testGetVariationOriginalFound( + Field $field, + APIVersionInfo $versionInfo, + string $variationName, + array $parameters + ): void { $expectedVariation = $this->createMock(ImageVariation::class); $this->ioResolver @@ -148,9 +170,17 @@ public function testGetVariationOriginalFound(Field $field, APIVersionInfo $vers /** * @dataProvider getVariationProvider + * + * @param array $parameters + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testGetVariationOriginalNotFound(Field $field, APIVersionInfo $versionInfo, string $variationName, array $parameters) - { + public function testGetVariationOriginalNotFound( + Field $field, + APIVersionInfo $versionInfo, + string $variationName, + array $parameters + ): void { $placeholderPath = '/tmp/placeholder.jpg'; $binaryCreateStruct = new BinaryFileCreateStruct(); $expectedVariation = $this->createMock(ImageVariation::class); @@ -161,34 +191,16 @@ public function testGetVariationOriginalNotFound(Field $field, APIVersionInfo $v ->with($field->value->id, IORepositoryResolver::VARIATION_ORIGINAL) ->willThrowException($this->createMock(NotResolvableException::class)); - $this->placeholderProvider - ->expects(self::once()) - ->method('getPlaceholder') - ->with($field->value, $this->placeholderOptions) - ->willReturn($placeholderPath); - - $this->ioService - ->expects(self::once()) - ->method('newBinaryCreateStructFromLocalFile') - ->with($placeholderPath) - ->willReturn($binaryCreateStruct); - - $this->ioService - ->expects(self::once()) - ->method('createBinaryFile') - ->with($binaryCreateStruct); - - $this->aliasGenerator->setPlaceholderProvider( - $this->placeholderProvider, - $this->placeholderOptions + $this->configurePlaceholderProvider( + $field, + $placeholderPath, + $binaryCreateStruct, + $versionInfo, + $variationName, + $parameters, + $expectedVariation ); - $this->innerAliasGenerator - ->expects(self::once()) - ->method('getVariation') - ->with($field, $versionInfo, $variationName, $parameters) - ->willReturn($expectedVariation); - $actualVariation = $this->aliasGenerator->getVariation( $field, $versionInfo, @@ -202,6 +214,10 @@ public function testGetVariationOriginalNotFound(Field $field, APIVersionInfo $v /** * @dataProvider getVariationProvider + * + * @param array $parameters + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ public function testGetVariationReturnsPlaceholderIfBinaryDataIsNotAvailable( Field $field, @@ -232,34 +248,16 @@ public function testGetVariationReturnsPlaceholderIfBinaryDataIsNotAvailable( ->with($binaryFile) ->willThrowException($this->createMock(NotFoundException::class)); - $this->placeholderProvider - ->expects(self::once()) - ->method('getPlaceholder') - ->with($field->value, $this->placeholderOptions) - ->willReturn($placeholderPath); - - $this->ioService - ->expects(self::once()) - ->method('newBinaryCreateStructFromLocalFile') - ->with($placeholderPath) - ->willReturn($binaryCreateStruct); - - $this->ioService - ->expects(self::once()) - ->method('createBinaryFile') - ->with($binaryCreateStruct); - - $this->aliasGenerator->setPlaceholderProvider( - $this->placeholderProvider, - $this->placeholderOptions + $this->configurePlaceholderProvider( + $field, + $placeholderPath, + $binaryCreateStruct, + $versionInfo, + $variationName, + $parameters, + $expectedVariation ); - $this->innerAliasGenerator - ->expects(self::once()) - ->method('getVariation') - ->with($field, $versionInfo, $variationName, $parameters) - ->willReturn($expectedVariation); - $actualVariation = $this->aliasGenerator->getVariation( $field, $versionInfo, @@ -274,12 +272,15 @@ public function testGetVariationReturnsPlaceholderIfBinaryDataIsNotAvailable( /** * @dataProvider supportsValueProvider */ - public function testSupportsValue(Value $value, bool $isSupported) + public function testSupportsValue(Value $value, bool $isSupported): void { self::assertSame($isSupported, $this->aliasGenerator->supportsValue($value)); } - public function supportsValueProvider(): array + /** + * @return array + */ + public static function supportsValueProvider(): array { return [ [new NullValue(), false], @@ -287,16 +288,62 @@ public function supportsValueProvider(): array ]; } - public function getVariationProvider(): array + /** + * @return array}> + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public static function getVariationProvider(): array { $field = new Field([ - 'value' => new ImageValue([ - 'id' => 'images/6/8/4/0/486-10-eng-GB/photo.jpg', - ]), - ]); + 'value' => new ImageValue([ + 'id' => 'images/6/8/4/0/486-10-eng-GB/photo.jpg', + ]), + ]); return [ [$field, new VersionInfo(), 'thumbnail', []], ]; } + + /** + * @param array $parameters + */ + private function configurePlaceholderProvider( + Field $field, + string $placeholderPath, + BinaryFileCreateStruct $binaryCreateStruct, + APIVersionInfo $versionInfo, + string $variationName, + array $parameters, + ImageVariation & MockObject $expectedVariation + ): void { + $this->placeholderProvider + ->expects(self::once()) + ->method('getPlaceholder') + ->with($field->value, $this->placeholderOptions) + ->willReturn($placeholderPath); + + $this->ioService + ->expects(self::once()) + ->method('newBinaryCreateStructFromLocalFile') + ->with($placeholderPath) + ->willReturn($binaryCreateStruct); + + $this->ioService + ->expects(self::once()) + ->method('createBinaryFile') + ->with($binaryCreateStruct); + + $this->aliasGenerator->setPlaceholderProvider( + $this->placeholderProvider, + $this->placeholderOptions + ); + + $this->innerAliasGenerator + ->expects(self::once()) + ->method('getVariation') + ->with($field, $versionInfo, $variationName, $parameters) + ->willReturn($expectedVariation); + } } diff --git a/tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php b/tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php index def720c8ad..350343f6e1 100644 --- a/tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php +++ b/tests/bundle/Core/Imagine/PlaceholderProvider/GenericProviderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\PlaceholderProvider; @@ -17,12 +18,17 @@ use Imagine\Image\Palette\Color\ColorInterface; use PHPUnit\Framework\TestCase; -class GenericProviderTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\PlaceholderProvider\GenericProvider + */ +final class GenericProviderTest extends TestCase { /** * @dataProvider getPlaceholderDataProvider + * + * @param array $options */ - public function testGetPlaceholder(ImageValue $value, $expectedText, array $options = []) + public function testGetPlaceholder(ImageValue $value, string $expectedText, array $options = []): void { $font = $this->createMock(AbstractFont::class); @@ -39,7 +45,7 @@ public function testGetPlaceholder(ImageValue $value, $expectedText, array $opti }); $font - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('box') ->willReturn($this->createMock(BoxInterface::class)); @@ -57,7 +63,7 @@ public function testGetPlaceholder(ImageValue $value, $expectedText, array $opti $drawer = $this->createMock(DrawerInterface::class); $image - ->expects(self::any()) + ->expects(self::atLeastOnce()) ->method('draw') ->willReturn($drawer); @@ -70,7 +76,12 @@ public function testGetPlaceholder(ImageValue $value, $expectedText, array $opti $provider->getPlaceholder($value, $options); } - public function getPlaceholderDataProvider() + /** + * @return array}> + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public static function getPlaceholderDataProvider(): array { return [ [ @@ -91,13 +102,16 @@ public function getPlaceholderDataProvider() ]; } - private function assertSizeEquals(array $expected, BoxInterface $actual) + /** + * @param array{int|null, int|null} $expected width, height + */ + private function assertSizeEquals(array $expected, BoxInterface $actual): void { self::assertEquals($expected[0], $actual->getWidth()); self::assertEquals($expected[1], $actual->getHeight()); } - private function assertColorEquals($expected, ColorInterface $actual) + private function assertColorEquals(string $expected, ColorInterface $actual): void { self::assertEquals(strtolower($expected), strtolower((string)$actual)); } diff --git a/tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php b/tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php index c5b421f6a3..54474d238e 100644 --- a/tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php +++ b/tests/bundle/Core/Imagine/PlaceholderProviderRegistryTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine; @@ -16,13 +17,13 @@ */ class PlaceholderProviderRegistryTest extends TestCase { - private const FOO = 'foo'; - private const BAR = 'bar'; + private const string FOO = 'foo'; + private const string BAR = 'bar'; /** * @depends testGetProviderKnown */ - public function testConstructor() + public function testConstructor(): void { $providers = [ self::FOO => $this->getPlaceholderProviderMock(), @@ -48,7 +49,7 @@ public function testAddProvider(): void self::assertSame($provider, $registry->getProvider(self::FOO)); } - public function testSupports() + public function testSupports(): void { $registry = new PlaceholderProviderRegistry([ 'supported' => $this->getPlaceholderProviderMock(), @@ -58,7 +59,7 @@ public function testSupports() self::assertFalse($registry->supports('unsupported')); } - public function testGetProviderKnown() + public function testGetProviderKnown(): void { $provider = $this->getPlaceholderProviderMock(); @@ -69,7 +70,7 @@ public function testGetProviderKnown() self::assertEquals($provider, $registry->getProvider(self::FOO)); } - public function testGetProviderUnknown() + public function testGetProviderUnknown(): void { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/bundle/Core/Imagine/VariationPathGenerator/AliasDirectoryVariationPathGeneratorTest.php b/tests/bundle/Core/Imagine/VariationPathGenerator/AliasDirectoryVariationPathGeneratorTest.php index fa6ecbec97..265459a431 100644 --- a/tests/bundle/Core/Imagine/VariationPathGenerator/AliasDirectoryVariationPathGeneratorTest.php +++ b/tests/bundle/Core/Imagine/VariationPathGenerator/AliasDirectoryVariationPathGeneratorTest.php @@ -4,15 +4,19 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\VariationPathGenerator; use Ibexa\Bundle\Core\Imagine\VariationPathGenerator\AliasDirectoryVariationPathGenerator; use PHPUnit\Framework\TestCase; -class AliasDirectoryVariationPathGeneratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\VariationPathGenerator\AliasDirectoryVariationPathGenerator + */ +final class AliasDirectoryVariationPathGeneratorTest extends TestCase { - public function testGetVariationPath() + public function testGetVariationPath(): void { $generator = new AliasDirectoryVariationPathGenerator(); diff --git a/tests/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGeneratorTest.php b/tests/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGeneratorTest.php index 88edae38c2..0386ec4a59 100644 --- a/tests/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGeneratorTest.php +++ b/tests/bundle/Core/Imagine/VariationPathGenerator/OriginalDirectoryVariationPathGeneratorTest.php @@ -4,15 +4,19 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\VariationPathGenerator; use Ibexa\Bundle\Core\Imagine\VariationPathGenerator\OriginalDirectoryVariationPathGenerator; use PHPUnit\Framework\TestCase; -class OriginalDirectoryVariationPathGeneratorTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\VariationPathGenerator\OriginalDirectoryVariationPathGenerator + */ +final class OriginalDirectoryVariationPathGeneratorTest extends TestCase { - public function testGetVariationPath() + public function testGetVariationPath(): void { $generator = new OriginalDirectoryVariationPathGenerator(); self::assertEquals( diff --git a/tests/bundle/Core/Imagine/VariationPathGenerator/WebpFormatVariationPathGeneratorTest.php b/tests/bundle/Core/Imagine/VariationPathGenerator/WebpFormatVariationPathGeneratorTest.php index d12c11c382..a8df87f645 100644 --- a/tests/bundle/Core/Imagine/VariationPathGenerator/WebpFormatVariationPathGeneratorTest.php +++ b/tests/bundle/Core/Imagine/VariationPathGenerator/WebpFormatVariationPathGeneratorTest.php @@ -18,8 +18,7 @@ final class WebpFormatVariationPathGeneratorTest extends TestCase { private VariationPathGenerator&MockObject $innerVariationPathGenerator; - /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration|\PHPUnit\Framework\MockObject\MockObject */ - private FilterConfiguration $filterConfiguration; + private FilterConfiguration & MockObject $filterConfiguration; protected function setUp(): void { diff --git a/tests/bundle/Core/Imagine/VariationPurger/IOVariationPurgerTest.php b/tests/bundle/Core/Imagine/VariationPurger/IOVariationPurgerTest.php index d38331268f..de882edd19 100644 --- a/tests/bundle/Core/Imagine/VariationPurger/IOVariationPurgerTest.php +++ b/tests/bundle/Core/Imagine/VariationPurger/IOVariationPurgerTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\VariationPurger; @@ -14,7 +15,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; -class IOVariationPurgerTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\VariationPurger\IOVariationPurger + */ +final class IOVariationPurgerTest extends TestCase { public function testPurgesAliasList(): void { diff --git a/tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php b/tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php index 66111770e4..1310c7980d 100644 --- a/tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php +++ b/tests/bundle/Core/Imagine/VariationPurger/ImageFileVariationPurgerTest.php @@ -4,26 +4,29 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\Core\Imagine\VariationPurger; use ArrayIterator; +use Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileList; use Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileVariationPurger; use Ibexa\Contracts\Core\Variation\VariationPathGenerator; use Ibexa\Core\IO\IOServiceInterface; use Ibexa\Core\IO\Values\BinaryFile; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ImageFileVariationPurgerTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileVariationPurger + */ +final class ImageFileVariationPurgerTest extends TestCase { - /** @var \Ibexa\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $ioServiceMock; + protected IOServiceInterface & MockObject $ioServiceMock; - /** @var \Ibexa\Contracts\Core\Variation\VariationPathGenerator|\PHPUnit\Framework\MockObject\MockObject */ - protected $pathGeneratorMock; + protected VariationPathGenerator & MockObject $pathGeneratorMock; - /** @var \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileVariationPurger */ - protected $purger; + protected ImageFileVariationPurger $purger; protected function setUp(): void { @@ -31,7 +34,7 @@ protected function setUp(): void $this->pathGeneratorMock = $this->createMock(VariationPathGenerator::class); } - public function testIteratesOverItems() + public function testIteratesOverItems(): void { $purger = $this->createPurger( [ @@ -53,7 +56,7 @@ public function testIteratesOverItems() $purger->purge(['large', 'gallery']); } - public function testPurgesExistingItem() + public function testPurgesExistingItem(): void { $purger = $this->createPurger( ['path/to/file.png'] @@ -62,17 +65,17 @@ public function testPurgesExistingItem() $this->pathGeneratorMock ->expects(self::once()) ->method('getVariationPath') - ->will(self::returnValue('path/to/file_large.png')); + ->willReturn('path/to/file_large.png'); $this->ioServiceMock ->expects(self::once()) ->method('exists') - ->will(self::returnValue(true)); + ->willReturn(true); $this->ioServiceMock ->expects(self::once()) ->method('loadBinaryFile') - ->will(self::returnValue(new BinaryFile())); + ->willReturn(new BinaryFile()); $this->ioServiceMock ->expects(self::once()) @@ -82,7 +85,7 @@ public function testPurgesExistingItem() $purger->purge(['large']); } - public function testDoesNotPurgeNotExistingItem() + public function testDoesNotPurgeNotExistingItem(): void { $purger = $this->createPurger( ['path/to/file.png'] @@ -91,12 +94,12 @@ public function testDoesNotPurgeNotExistingItem() $this->pathGeneratorMock ->expects(self::once()) ->method('getVariationPath') - ->will(self::returnValue('path/to/file_large.png')); + ->willReturn('path/to/file_large.png'); $this->ioServiceMock ->expects(self::once()) ->method('exists') - ->will(self::returnValue(false)); + ->willReturn(false); $this->ioServiceMock ->expects(self::never()) @@ -109,8 +112,14 @@ public function testDoesNotPurgeNotExistingItem() $purger->purge(['large']); } - private function createPurger(array $fileList) + /** + * @param string[] $fileList + */ + private function createPurger(array $fileList): ImageFileVariationPurger { - return new ImageFileVariationPurger(new ArrayIterator($fileList), $this->ioServiceMock, $this->pathGeneratorMock); + $imageFileList = new class($fileList) extends ArrayIterator implements ImageFileList { + }; + + return new ImageFileVariationPurger($imageFileList, $this->ioServiceMock, $this->pathGeneratorMock); } } diff --git a/tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php b/tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php index 73b77a6638..df0ae13b76 100644 --- a/tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php +++ b/tests/bundle/Core/Imagine/VariationPurger/LegacyStorageImageFileListTest.php @@ -12,43 +12,39 @@ use Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\IO\IOConfigProvider; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class LegacyStorageImageFileListTest extends TestCase +/** + * @covers \Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList + */ +final class LegacyStorageImageFileListTest extends TestCase { - /** @var \Ibexa\Bundle\Core\Imagine\VariationPurger\ImageFileRowReader|\PHPUnit\Framework\MockObject\MockObject */ - protected $rowReaderMock; - - /** @var \Ibexa\Bundle\Core\Imagine\VariationPurger\LegacyStorageImageFileList */ - protected $fileList; - - /** @var \Ibexa\Core\IO\IOConfigProvider|\PHPUnit\Framework\MockObject\MockObject */ - private $ioConfigResolverMock; + protected ImageFileRowReader&MockObject $rowReaderMock; - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $configResolverMock; + protected LegacyStorageImageFileList $fileList; protected function setUp(): void { $this->rowReaderMock = $this->createMock(ImageFileRowReader::class); - $this->ioConfigResolverMock = $this->createMock(IOConfigProvider::class); - $this->ioConfigResolverMock + $ioConfigResolverMock = $this->createMock(IOConfigProvider::class); + $ioConfigResolverMock ->method('getLegacyUrlPrefix') ->willReturn('var/ibexa_demo_site/storage'); - $this->configResolverMock = $this->createMock(ConfigResolverInterface::class); - $this->configResolverMock + $configResolverMock = $this->createMock(ConfigResolverInterface::class); + $configResolverMock ->method('getParameter') ->with('image.published_images_dir') ->willReturn('images'); $this->fileList = new LegacyStorageImageFileList( $this->rowReaderMock, - $this->ioConfigResolverMock, - $this->configResolverMock + $ioConfigResolverMock, + $configResolverMock ); } - public function testIterator() + public function testIterator(): void { $expected = [ 'path/to/1st/image.jpg', @@ -62,9 +58,9 @@ public function testIterator() } /** - * Tests that the iterator transforms the ezimagefile value into a binaryfile id. + * Tests that the iterator transforms the ibexa_image_file value into a binary file id. */ - public function testImageIdTransformation() + public function testImageIdTransformation(): void { $this->configureRowReaderMock(['var/ibexa_demo_site/storage/images/path/to/1st/image.jpg']); foreach ($this->fileList as $file) { @@ -72,11 +68,26 @@ public function testImageIdTransformation() } } - private function configureRowReaderMock(array $fileList) + /** + * @param string[] $fileList + */ + private function configureRowReaderMock(array $fileList): void { - $mockInvocator = $this->rowReaderMock->expects(self::any())->method('getRow'); - call_user_func_array([$mockInvocator, 'willReturnOnConsecutiveCalls'], $fileList); + $fileListCount = count($fileList); + // iterator will try to invoke methods one more time to establish its end + $expectedIteratorInvocationsCount = $fileListCount + 1; + + $index = 0; + $this->rowReaderMock + ->expects(self::exactly($expectedIteratorInvocationsCount)) + ->method('getRow') + ->willReturnCallback(static function () use (&$index, $fileList): ?string { + return $fileList[$index++] ?? null; + }); - $this->rowReaderMock->expects(self::any())->method('getCount')->willReturn(count($fileList)); + $this->rowReaderMock + ->expects(self::exactly($expectedIteratorInvocationsCount)) + ->method('getCount') + ->willReturn($fileListCount); } } diff --git a/tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php b/tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php index 28855e616b..d5d187c657 100644 --- a/tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php +++ b/tests/bundle/IO/DependencyInjection/Compiler/IOConfigurationPassTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection\Compiler; @@ -11,17 +12,19 @@ use Ibexa\Bundle\IO\DependencyInjection\Compiler\IOConfigurationPass; use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -class IOConfigurationPassTest extends AbstractCompilerPassTestCase +/** + * @covers \Ibexa\Bundle\IO\DependencyInjection\Compiler\IOConfigurationPass + */ +final class IOConfigurationPassTest extends AbstractCompilerPassTestCase { - /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory|\PHPUnit\Framework\MockObject\MockObject */ - protected $metadataConfigurationFactoryMock; + protected ConfigurationFactory & MockObject $metadataConfigurationFactoryMock; - /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory|\PHPUnit\Framework\MockObject\MockObject */ - protected $binarydataConfigurationFactoryMock; + protected ConfigurationFactory & MockObject $binarydataConfigurationFactoryMock; protected function setUp(): void { @@ -42,9 +45,12 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass( new IOConfigurationPass( + // workaround for ArrayObject TValue not being template-covariant (can't pass a mock) + /** @phpstan-ignore argument.type */ new ArrayObject( ['test_handler' => $this->metadataConfigurationFactoryMock] ), + /** @phpstan-ignore argument.type */ new ArrayObject( ['test_handler' => $this->binarydataConfigurationFactoryMock] ) @@ -55,7 +61,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void /** * Tests that the default handlers are available when nothing is configured. */ - public function testDefaultHandlers() + public function testDefaultHandlers(): void { $this->compile(); @@ -72,7 +78,7 @@ public function testDefaultHandlers() ); } - public function testBinarydataHandler() + public function testBinarydataHandler(): void { $this->container->setParameter( 'ibexa.io.binarydata_handlers', @@ -82,7 +88,7 @@ public function testBinarydataHandler() $this->binarydataConfigurationFactoryMock ->expects(self::once()) ->method('getParentServiceId') - ->will(self::returnValue('test.io.binarydata_handler.test_handler')); + ->willReturn('test.io.binarydata_handler.test_handler'); $this->compile(); @@ -92,7 +98,7 @@ public function testBinarydataHandler() ); } - public function testMetadataHandler() + public function testMetadataHandler(): void { $this->container->setParameter( 'ibexa.io.metadata_handlers', @@ -102,7 +108,7 @@ public function testMetadataHandler() $this->metadataConfigurationFactoryMock ->expects(self::once()) ->method('getParentServiceId') - ->will(self::returnValue('test.io.metadata_handler.test_handler')); + ->willReturn('test.io.metadata_handler.test_handler'); $this->compile(); @@ -112,7 +118,7 @@ public function testMetadataHandler() ); } - public function testUnknownMetadataHandler() + public function testUnknownMetadataHandler(): void { $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage('Unknown handler'); @@ -125,7 +131,7 @@ public function testUnknownMetadataHandler() $this->compile(); } - public function testUnknownBinarydataHandler() + public function testUnknownBinarydataHandler(): void { $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage('Unknown handler'); diff --git a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php index f574fd6429..3cfb37503a 100644 --- a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php +++ b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BaseFlysystemTestCase.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactory; @@ -13,11 +14,11 @@ abstract class BaseFlysystemTestCase extends ConfigurationFactoryTestCase { - private $flysystemAdapterServiceId = 'oneup_flysystem.test_adapter'; + private string $flysystemAdapterServiceId = 'oneup_flysystem.test_adapter'; private string $filesystemServiceId = 'ibexa.core.io.flysystem.my_test_handler_filesystem'; - public function provideHandlerConfiguration() + public function provideHandlerConfiguration(): array { $this->setDefinition($this->flysystemAdapterServiceId, new Definition()); @@ -26,15 +27,15 @@ public function provideHandlerConfiguration() ]; } - public function provideParentServiceDefinition() + public function provideParentServiceDefinition(): Definition { return new Definition(null, [null]); } - public function validateConfiguredHandler($handlerDefinitionId) + public function validateConfiguredHandler(string $handlerServiceId): void { - self::assertContainerBuilderHasServiceDefinitionWithArgument( - $handlerDefinitionId, + $this->assertContainerBuilderHasServiceDefinitionWithArgument( + $handlerServiceId, 0, new Reference($this->filesystemServiceId) ); diff --git a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/FlysystemTest.php b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/FlysystemTest.php index 8bed235dca..7ad910a041 100644 --- a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/FlysystemTest.php +++ b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/BinarydataHandler/FlysystemTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactory\BinarydataHandler; @@ -17,9 +18,6 @@ public function provideTestedFactory(): Flysystem return new Flysystem(); } - /** - * Returns the expected parent service id. - */ public function provideExpectedParentServiceId(): string { return 'ibexa.core.io.binarydata_handler.flysystem'; diff --git a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/FlysystemTest.php b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/FlysystemTest.php index fb745f670d..f01cebc4e3 100644 --- a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/FlysystemTest.php +++ b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/FlysystemTest.php @@ -4,26 +4,21 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler; +use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory; use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler\Flysystem; +use Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactory\BaseFlysystemTestCase; -class FlysystemTest +class FlysystemTest extends BaseFlysystemTestCase { - /** - * Returns an instance of the tested factory. - * - * @return \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler\Flysystem - */ - public function provideTestedFactory() + public function provideTestedFactory(): ConfigurationFactory { return new Flysystem(); } - /** - * Returns the expected parent service id. - */ public function provideExpectedParentServiceId(): string { return 'ibexa.core.io.metadata_handler.flysystem'; diff --git a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php index b8a9514089..df3e04c0c2 100644 --- a/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php +++ b/tests/bundle/IO/DependencyInjection/ConfigurationFactory/MetadataHandler/LegacyDFSClusterTest.php @@ -4,37 +4,35 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler; -use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler\LegacyDFSCluster; +use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory; +use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory\MetadataHandler\LegacyDFSCluster as LegacyDFSClusterConfigurationFactory; +use Ibexa\Core\IO\IOMetadataHandler\LegacyDFSCluster; use Ibexa\Tests\Bundle\IO\DependencyInjection\ConfigurationFactoryTestCase; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; final class LegacyDFSClusterTest extends ConfigurationFactoryTestCase { - /** - * Returns an instance of the tested factory. - * - * @return \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory - */ - public function provideTestedFactory() + public function provideTestedFactory(): ConfigurationFactory { - return new LegacyDFSCluster(); + return new LegacyDFSClusterConfigurationFactory(); } public function provideExpectedParentServiceId(): string { - return \Ibexa\Core\IO\IOMetadataHandler\LegacyDFSCluster::class; + return LegacyDFSCluster::class; } - public function provideParentServiceDefinition() + public function provideParentServiceDefinition(): Definition { return new Definition(null, [null]); } - public function provideHandlerConfiguration() + public function provideHandlerConfiguration(): array { return ['connection' => 'doctrine.dbal.test_connection']; } @@ -46,9 +44,9 @@ public function provideHandlerConfiguration() * * @param string $handlerServiceId id of the service that was registered by the compiler pass */ - public function validateConfiguredHandler($handlerServiceId) + public function validateConfiguredHandler(string $handlerServiceId): void { - self::assertContainerBuilderHasServiceDefinitionWithArgument( + $this->assertContainerBuilderHasServiceDefinitionWithArgument( $handlerServiceId, 0, new Reference('doctrine.dbal.test_connection') diff --git a/tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php b/tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php index f7150000aa..8344754380 100644 --- a/tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php +++ b/tests/bundle/IO/DependencyInjection/ConfigurationFactoryTestCase.php @@ -4,11 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\DependencyInjection; +use Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractContainerBuilderTestCase; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\DependencyInjection\Definition; /** * Abstract class for testing ConfigurationFactory implementations. @@ -17,8 +20,7 @@ */ abstract class ConfigurationFactoryTestCase extends AbstractContainerBuilderTestCase { - /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory */ - protected $factory; + protected ConfigurationFactory $factory; protected function setUp(): void { @@ -27,7 +29,7 @@ protected function setUp(): void $this->factory = $this->provideTestedFactory(); } - public function testGetParentServiceId() + public function testGetParentServiceId(): void { self::assertEquals( $this->provideExpectedParentServiceId(), @@ -35,16 +37,16 @@ public function testGetParentServiceId() ); } - public function testAddConfiguration() + public function testAddConfiguration(): void { $node = new ArrayNodeDefinition('handler'); $this->factory->addConfiguration($node); - self::assertInstanceOf(ArrayNodeDefinition::class, $node); + self::assertNotEmpty($node->getChildNodeDefinitions()); // @todo customized testing of configuration node ? } - public function testConfigureHandler() + public function testConfigureHandler(): void { $handlerConfiguration = $this->provideHandlerConfiguration() + @@ -60,7 +62,7 @@ public function testConfigureHandler() /** * Registers the handler in the container, like the pass would have done. */ - private function registerHandler($name): string + private function registerHandler(string $name): string { $this->setDefinition($this->provideExpectedParentServiceId(), $this->provideParentServiceDefinition()); $handlerServiceId = sprintf('%s.%s', $this->provideExpectedParentServiceId(), $name); @@ -71,10 +73,8 @@ private function registerHandler($name): string /** * Returns an instance of the tested factory. - * - * @return \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory */ - abstract public function provideTestedFactory(); + abstract public function provideTestedFactory(): ConfigurationFactory; /** * Returns the expected parent service id. @@ -84,10 +84,8 @@ abstract public function provideExpectedParentServiceId(); /** * Provides the parent service definition, as defined in the bundle's services definition. * Required so that getArguments / replaceCalls work correctly. - * - * @return \Symfony\Component\DependencyInjection\Definition */ - abstract public function provideParentServiceDefinition(); + abstract public function provideParentServiceDefinition(): Definition; /** * Provides the configuration array given to the handler, and initializes the container. @@ -95,9 +93,9 @@ abstract public function provideParentServiceDefinition(); * * The method can also configure the container via $this->container. * - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container + * @return array */ - abstract public function provideHandlerConfiguration(); + abstract public function provideHandlerConfiguration(): array; /** * Lets you test the handler definition after it was configured. @@ -106,5 +104,5 @@ abstract public function provideHandlerConfiguration(); * * @param string $handlerServiceId id of the service that was registered by the compiler pass */ - abstract public function validateConfiguredHandler($handlerServiceId); + abstract public function validateConfiguredHandler(string $handlerServiceId): void; } diff --git a/tests/bundle/IO/EventListener/StreamFileListenerTest.php b/tests/bundle/IO/EventListener/StreamFileListenerTest.php index 11e35fece6..9c5b59a7de 100644 --- a/tests/bundle/IO/EventListener/StreamFileListenerTest.php +++ b/tests/bundle/IO/EventListener/StreamFileListenerTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\IO\EventListener; @@ -19,7 +20,10 @@ use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -class StreamFileListenerTest extends TestCase +/** + * @covers \Ibexa\Bundle\IO\EventListener\StreamFileListener + */ +final class StreamFileListenerTest extends TestCase { private StreamFileListener $eventListener; @@ -36,6 +40,9 @@ protected function setUp(): void $this->eventListener = new StreamFileListener($this->ioServiceMock, $this->ioConfigResolverMock); } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ public function testDoesNotRespondToNonIoUri(): void { $request = $this->createRequest('/Not-an-image'); @@ -51,6 +58,9 @@ public function testDoesNotRespondToNonIoUri(): void self::assertNull($event->getResponse()); } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ public function testDoesNotRespondToNoIoRequest(): void { $request = $this->createRequest('/Not-an-image', 'bar.fr'); @@ -66,6 +76,9 @@ public function testDoesNotRespondToNoIoRequest(): void self::assertNull($event->getResponse()); } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ public function testRespondsToIoUri(): void { $uri = $binaryFileUri = '/var/test/storage/images/image.png'; @@ -75,6 +88,9 @@ public function testRespondsToIoUri(): void $this->assertOnKernelRequestResponse($request, $urlPrefix, $binaryFileUri); } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ public function testRespondsToIoRequest(): void { $uri = '/var/test/storage/images/image.png'; @@ -109,6 +125,9 @@ protected function createEvent(Request $request): RequestEvent ); } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ private function assertOnKernelRequestResponse(Request $request, string $urlPrefix, string $binaryFileUri): void { $this->configureIoUrlPrefix($urlPrefix); diff --git a/tests/bundle/IO/Migration/FileMigratorTest.php b/tests/bundle/IO/Migration/FileMigratorTest.php index 34e1dcb176..3fdf38ffa5 100644 --- a/tests/bundle/IO/Migration/FileMigratorTest.php +++ b/tests/bundle/IO/Migration/FileMigratorTest.php @@ -14,30 +14,30 @@ use Ibexa\Contracts\Core\IO\BinaryFile; use Ibexa\Core\IO\IOBinarydataHandler; use Ibexa\Core\IO\IOMetadataHandler; +use Ibexa\Core\IO\IOMetadataHandler\Flysystem; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +/** + * @covers \Ibexa\Bundle\IO\Migration\MigrationHandler + */ final class FileMigratorTest extends TestCase { - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry|\PHPUnit\Framework\MockObject\MockObject */ - private $metadataHandlerRegistry; + /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOMetadataHandler>&\PHPUnit\Framework\MockObject\MockObject */ + private HandlerRegistry & MockObject $metadataHandlerRegistry; - /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry|\PHPUnit\Framework\MockObject\MockObject */ - private $binaryHandlerRegistry; + /** @var \Ibexa\Bundle\IO\ApiLoader\HandlerRegistry<\Ibexa\Core\IO\IOBinarydataHandler>&\PHPUnit\Framework\MockObject\MockObject */ + private HandlerRegistry & MockObject $binaryHandlerRegistry; - /** @var \Ibexa\Bundle\IO\Migration\FileMigratorInterface */ - private $fileMigrator; + private FileMigrator $fileMigrator; - /** @var \Ibexa\Core\IO\IOMetadataHandler\Flysystem */ - private $metadataFlysystem; + private Flysystem & MockObject $metadataFlysystem; - /** @var \Ibexa\Core\IO\IOMetadataHandler\LegacyDFSCluster */ - private $metadataLegacyDFSCluster; + private IOMetadataHandler\LegacyDFSCluster&MockObject $metadataLegacyDFSCluster; - /** @var \Ibexa\Core\IO\IOBinarydataHandler\Flysystem */ - private $binaryFlysystemFrom; + private IOBinarydataHandler & MockObject $binaryFlysystemFrom; - /** @var \Ibexa\Core\IO\IOBinarydataHandler\Flysystem */ - private $binaryFlysystemTo; + private IOBinarydataHandler & MockObject $binaryFlysystemTo; protected function setUp(): void { @@ -46,7 +46,7 @@ protected function setUp(): void $this->metadataHandlerRegistry = $this->createMock(HandlerRegistry::class); $this->binaryHandlerRegistry = $this->createMock(HandlerRegistry::class); - $this->metadataFlysystem = $this->createMock(IOMetadataHandler\Flysystem::class); + $this->metadataFlysystem = $this->createMock(Flysystem::class); $this->metadataLegacyDFSCluster = $this->createMock(IOMetadataHandler\LegacyDFSCluster::class); $this->binaryFlysystemFrom = $this->createMock(IOBinarydataHandler::class); @@ -60,25 +60,21 @@ public function testMigrateFile(): void $this->metadataHandlerRegistry ->expects(self::exactly(2)) ->method('getConfiguredHandler') - ->withConsecutive( - ['default'], - ['dfs'] - ) - ->willReturnOnConsecutiveCalls( - $this->metadataFlysystem, - $this->metadataLegacyDFSCluster + ->willReturnMap( + [ + ['default', $this->metadataFlysystem], + ['dfs', $this->metadataLegacyDFSCluster], + ] ); $this->binaryHandlerRegistry ->expects(self::exactly(2)) ->method('getConfiguredHandler') - ->withConsecutive( - ['default'], - ['nfs'] - ) - ->willReturnOnConsecutiveCalls( - $this->binaryFlysystemFrom, - $this->binaryFlysystemTo + ->willReturnMap( + [ + ['default', $this->binaryFlysystemFrom], + ['nfs', $this->binaryFlysystemTo], + ] ); $this->fileMigrator->setIODataHandlersByIdentifiers('default', 'default', 'dfs', 'nfs'); @@ -107,30 +103,18 @@ public function testSkipMigratingIfSameHandlers(): void $this->metadataHandlerRegistry ->expects(self::exactly(2)) ->method('getConfiguredHandler') - ->withConsecutive( - ['default'], - ['default'] - ) - ->willReturnOnConsecutiveCalls( - $this->metadataFlysystem, - $this->metadataFlysystem - ); + ->with('default') + ->willReturn($this->metadataFlysystem); $this->binaryHandlerRegistry ->expects(self::exactly(2)) ->method('getConfiguredHandler') - ->withConsecutive( - ['default'], - ['default'] - ) - ->willReturnOnConsecutiveCalls( - $this->binaryFlysystemFrom, - $this->binaryFlysystemFrom - ); + ->with('default')->willReturn($this->binaryFlysystemFrom); $this->fileMigrator->setIODataHandlersByIdentifiers('default', 'default', 'default', 'default'); $binaryFile = new BinaryFile(); + $binaryFile->id = 'foo/bar.pdf'; $this->binaryFlysystemFrom ->expects(self::never()) diff --git a/tests/integration/Core/FieldType/FieldConstraintsStorage/Stub/ExampleFieldType.php b/tests/integration/Core/FieldType/FieldConstraintsStorage/Stub/ExampleFieldType.php index d786ac5fa9..27dc3ca155 100644 --- a/tests/integration/Core/FieldType/FieldConstraintsStorage/Stub/ExampleFieldType.php +++ b/tests/integration/Core/FieldType/FieldConstraintsStorage/Stub/ExampleFieldType.php @@ -14,7 +14,7 @@ final class ExampleFieldType extends FieldType { - public const FIELD_TYPE_IDENTIFIER = 'example'; + public const string FIELD_TYPE_IDENTIFIER = 'example'; protected function createValueFromInput($inputValue): ExampleFieldTypeValue { @@ -31,12 +31,12 @@ public function getName(Value $value, FieldDefinition $fieldDefinition, string $ return ''; } - public function getEmptyValue(): ExampleFieldTypeValue + public function getEmptyValue(): Value { return new ExampleFieldTypeValue(); } - public function fromHash($hash): ExampleFieldTypeValue + public function fromHash(mixed $hash): Value { return new ExampleFieldTypeValue(); } @@ -46,7 +46,7 @@ protected function checkValueStructure(Value $value): void // Nothing to do here. } - public function toHash(Value $value) + public function toHash(Value $value): null { return null; } @@ -56,12 +56,12 @@ protected static function checkValueType($value): void // Nothing to do here. } - public function validateFieldSettings($fieldSettings): array + public function validateFieldSettings(array $fieldSettings): array { return []; } - public function validateValidatorConfiguration($validatorConfiguration): array + public function validateValidatorConfiguration(mixed $validatorConfiguration): array { return []; } diff --git a/tests/lib/FieldType/Generic/Stubs/Value.php b/tests/lib/FieldType/Generic/Stubs/Value.php index cda857ccb0..f830e8302d 100644 --- a/tests/lib/FieldType/Generic/Stubs/Value.php +++ b/tests/lib/FieldType/Generic/Stubs/Value.php @@ -12,19 +12,19 @@ final class Value implements ValueInterface { - private $value; + private mixed $value; - public function __construct($value = null) + public function __construct(mixed $value = null) { $this->value = $value; } - public function getValue() + public function getValue(): mixed { return $this->value; } - public function __toString() + public function __toString(): string { return (string)$this->value; } diff --git a/tests/lib/FieldType/Image/IO/LegacyTest.php b/tests/lib/FieldType/Image/IO/LegacyTest.php index 33a74ea5b1..682c2f8948 100644 --- a/tests/lib/FieldType/Image/IO/LegacyTest.php +++ b/tests/lib/FieldType/Image/IO/LegacyTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Core\FieldType\Image\IO; @@ -14,26 +15,25 @@ use Ibexa\Core\IO\IOServiceInterface; use Ibexa\Core\IO\Values\BinaryFile; use Ibexa\Core\IO\Values\BinaryFileCreateStruct; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class LegacyTest extends TestCase +/** + * @covers \Ibexa\Core\FieldType\Image\IO\Legacy + */ +final class LegacyTest extends TestCase { - /** @var \Ibexa\Core\FieldType\Image\IO\Legacy */ - protected $service; + protected LegacyIOService $service; /** * Internal IOService instance for published images. - * - * @var \Ibexa\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $publishedIoServiceMock; + protected IOServiceInterface & MockObject $publishedIoServiceMock; /** * Internal IOService instance for draft images. - * - * @var \Ibexa\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $draftIoServiceMock; + protected IOServiceInterface & MockObject $draftIoServiceMock; protected function setUp(): void { @@ -47,7 +47,10 @@ protected function setUp(): void ); } - public function testNewBinaryCreateStructFromLocalFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public function testNewBinaryCreateStructFromLocalFile(): void { $path = '/tmp/file.png'; $struct = new BinaryFileCreateStruct(); @@ -55,7 +58,7 @@ public function testNewBinaryCreateStructFromLocalFile() ->expects(self::once()) ->method('newBinaryCreateStructFromLocalFile') ->with($path) - ->will(self::returnValue($struct)); + ->willReturn($struct); $this->draftIoServiceMock->expects(self::never())->method('newBinaryCreateStructFromLocalFile'); @@ -65,14 +68,14 @@ public function testNewBinaryCreateStructFromLocalFile() ); } - public function testExists() + public function testExists(): void { $path = 'path/file.png'; $this->publishedIoServiceMock ->expects(self::once()) ->method('exists') ->with($path) - ->will(self::returnValue(true)); + ->willReturn(true); $this->draftIoServiceMock->expects(self::never())->method('exists'); @@ -83,8 +86,10 @@ public function testExists() /** * Standard binary file, with regular id. + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testLoadBinaryFile() + public function testLoadBinaryFile(): void { $id = 'path/file.jpg'; $binaryFile = new BinaryFile(['id' => $id]); @@ -93,7 +98,7 @@ public function testLoadBinaryFile() ->expects(self::once()) ->method('loadBinaryFile') ->with($id) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); $this->draftIoServiceMock->expects(self::never())->method('loadBinaryFile'); @@ -104,9 +109,11 @@ public function testLoadBinaryFile() } /** - * Load from internal draft binary file path. + * Load from an internal draft binary file path. + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testLoadBinaryFileDraftInternalPath() + public function testLoadBinaryFileDraftInternalPath(): void { $internalId = 'var/test/storage/images-versioned/path/file.jpg'; $id = 'path/file.jpg'; @@ -116,7 +123,7 @@ public function testLoadBinaryFileDraftInternalPath() ->expects(self::once()) ->method('loadBinaryFileByUri') ->with($internalId) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); $this->publishedIoServiceMock->expects(self::never())->method('loadBinaryFile'); @@ -127,9 +134,11 @@ public function testLoadBinaryFileDraftInternalPath() } /** - * Load from internal published binary file path. + * Load from an internal published binary file path. + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testLoadBinaryFilePublishedInternalPath() + public function testLoadBinaryFilePublishedInternalPath(): void { $internalId = 'var/test/storage/images/path/file.jpg'; $id = 'path/file.jpg'; @@ -139,7 +148,7 @@ public function testLoadBinaryFilePublishedInternalPath() ->expects(self::once()) ->method('loadBinaryFileByUri') ->with($internalId) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); $this->draftIoServiceMock->expects(self::never())->method('loadBinaryFile'); @@ -150,9 +159,11 @@ public function testLoadBinaryFilePublishedInternalPath() } /** - * Load from external draft binary file path. + * Load from an external draft binary file path. + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testLoadBinaryFileDraftExternalPath() + public function testLoadBinaryFileDraftExternalPath(): void { $id = 'path/file.jpg'; $binaryFile = new BinaryFile(['id' => $id]); @@ -161,13 +172,13 @@ public function testLoadBinaryFileDraftExternalPath() ->expects(self::once()) ->method('loadBinaryFile') ->with($id) - ->will(self::throwException(new InvalidArgumentException('binaryFileId', "Can't find file with id $id}"))); + ->willThrowException(new InvalidArgumentException('binaryFileId', "Can't find file with id $id")); $this->draftIoServiceMock ->expects(self::once()) ->method('loadBinaryFile') ->with($id) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); self::assertSame( $binaryFile, @@ -175,7 +186,10 @@ public function testLoadBinaryFileDraftExternalPath() ); } - public function testLoadBinaryFileByUriWithPublishedFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testLoadBinaryFileByUriWithPublishedFile(): void { $binaryFileUri = 'var/test/images/an/image.png'; $binaryFile = new BinaryFile(['id' => 'an/image.png']); @@ -183,7 +197,7 @@ public function testLoadBinaryFileByUriWithPublishedFile() ->expects(self::once()) ->method('loadBinaryFileByUri') ->with($binaryFileUri) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); self::assertSame( $binaryFile, @@ -191,7 +205,10 @@ public function testLoadBinaryFileByUriWithPublishedFile() ); } - public function testLoadBinaryFileByUriWithDraftFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testLoadBinaryFileByUriWithDraftFile(): void { $binaryFileUri = 'var/test/images-versioned/an/image.png'; $binaryFile = new BinaryFile(['id' => 'an/image.png']); @@ -206,7 +223,7 @@ public function testLoadBinaryFileByUriWithDraftFile() ->expects(self::once()) ->method('loadBinaryFileByUri') ->with($binaryFileUri) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); self::assertSame( $binaryFile, @@ -214,7 +231,10 @@ public function testLoadBinaryFileByUriWithDraftFile() ); } - public function testGetFileContents() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetFileContents(): void { $contents = 'some contents'; $path = 'path/file.png'; @@ -224,13 +244,13 @@ public function testGetFileContents() ->expects(self::once()) ->method('exists') ->with($path) - ->will(self::returnValue(false)); + ->willReturn(false); $this->publishedIoServiceMock ->expects(self::once()) ->method('getFileContents') ->with($binaryFile) - ->will(self::returnValue($contents)); + ->willReturn($contents); $this->draftIoServiceMock->expects(self::never())->method('getFileContents'); @@ -240,7 +260,10 @@ public function testGetFileContents() ); } - public function testGetFileContentsOfDraft() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetFileContentsOfDraft(): void { $contents = 'some contents'; $path = 'path/file.png'; @@ -250,13 +273,13 @@ public function testGetFileContentsOfDraft() ->expects(self::once()) ->method('exists') ->with($path) - ->will(self::returnValue(true)); + ->willReturn(true); $this->draftIoServiceMock ->expects(self::once()) ->method('getFileContents') ->with($binaryFile) - ->will(self::returnValue($contents)); + ->willReturn($contents); $this->publishedIoServiceMock->expects(self::never())->method('getFileContents'); @@ -266,7 +289,10 @@ public function testGetFileContentsOfDraft() ); } - public function testGetMimeType() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetMimeType(): void { $path = 'path/file.png'; $mimeType = 'image/png'; @@ -275,13 +301,13 @@ public function testGetMimeType() ->expects(self::once()) ->method('exists') ->with($path) - ->will(self::returnValue(false)); + ->willReturn(false); $this->publishedIoServiceMock ->expects(self::once()) ->method('getMimeType') ->with($path) - ->will(self::returnValue($mimeType)); + ->willReturn($mimeType); $this->draftIoServiceMock->expects(self::never())->method('getMimeType'); @@ -291,7 +317,10 @@ public function testGetMimeType() ); } - public function testGetMimeTypeOfDraft() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetMimeTypeOfDraft(): void { $path = 'path/file.png'; $mimeType = 'image/png'; @@ -300,13 +329,13 @@ public function testGetMimeTypeOfDraft() ->expects(self::once()) ->method('exists') ->with($path) - ->will(self::returnValue(true)); + ->willReturn(true); $this->draftIoServiceMock ->expects(self::once()) ->method('getMimeType') ->with($path) - ->will(self::returnValue($mimeType)); + ->willReturn($mimeType); $this->publishedIoServiceMock->expects(self::never())->method('getMimeType'); @@ -316,7 +345,10 @@ public function testGetMimeTypeOfDraft() ); } - public function testCreateBinaryFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testCreateBinaryFile(): void { $createStruct = new BinaryFileCreateStruct(); $binaryFile = new BinaryFile(); @@ -325,7 +357,7 @@ public function testCreateBinaryFile() ->expects(self::once()) ->method('createBinaryFile') ->with($createStruct) - ->will(self::returnValue($binaryFile)); + ->willReturn($binaryFile); $this->draftIoServiceMock->expects(self::never())->method('createBinaryFile'); @@ -335,31 +367,34 @@ public function testCreateBinaryFile() ); } - public function testGetUri() + public function testGetUri(): void { - $binaryFile = new BinaryFile(); + $binaryFile = new BinaryFile(['id' => 'foo']); $this->publishedIoServiceMock ->expects(self::once()) ->method('getUri') - ->with($binaryFile) - ->will(self::returnValue('protocol://uri')); + ->with($binaryFile->getId()) + ->willReturn('protocol://uri'); $this->draftIoServiceMock->expects(self::never())->method('getUri'); self::assertEquals( 'protocol://uri', - $this->service->getUri($binaryFile) + $this->service->getUri($binaryFile->getId()) ); } - public function testGetFileInputStream() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testGetFileInputStream(): void { $binaryFile = new BinaryFile(); $this->publishedIoServiceMock ->expects(self::once()) ->method('getFileInputStream') ->with($binaryFile) - ->will(self::returnValue('resource')); + ->willReturn('resource'); $this->draftIoServiceMock->expects(self::never())->method('getFileInputStream'); @@ -369,7 +404,10 @@ public function testGetFileInputStream() ); } - public function testDeleteBinaryFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testDeleteBinaryFile(): void { $binaryFile = new BinaryFile(); $this->publishedIoServiceMock @@ -382,14 +420,17 @@ public function testDeleteBinaryFile() $this->service->deleteBinaryFile($binaryFile); } - public function testNewBinaryCreateStructFromUploadedFile() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testNewBinaryCreateStructFromUploadedFile(): void { $struct = new BinaryFileCreateStruct(); $this->publishedIoServiceMock ->expects(self::once()) ->method('newBinaryCreateStructFromUploadedFile') ->with([]) - ->will(self::returnValue($struct)); + ->willReturn($struct); $this->draftIoServiceMock->expects(self::never())->method('newBinaryCreateStructFromUploadedFile'); @@ -399,10 +440,7 @@ public function testNewBinaryCreateStructFromUploadedFile() ); } - /** - * @return \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject - */ - protected function createConfigResolverMock(): ConfigResolverInterface + protected function createConfigResolverMock(): ConfigResolverInterface & MockObject { $mock = $this->createMock(ConfigResolverInterface::class); $mock diff --git a/tests/lib/IO/IOBinarydataHandler/FlysystemTest.php b/tests/lib/IO/IOBinarydataHandler/FlysystemTest.php index e09f9f9bbe..f0bd268204 100644 --- a/tests/lib/IO/IOBinarydataHandler/FlysystemTest.php +++ b/tests/lib/IO/IOBinarydataHandler/FlysystemTest.php @@ -15,15 +15,14 @@ use League\Flysystem\FilesystemOperator; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToReadFile; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FlysystemTest extends TestCase { - /** @var \Ibexa\Core\IO\IOBinarydataHandler|\PHPUnit\Framework\MockObject\MockObject */ private IOBinarydataHandler $handler; - /** @var \League\Flysystem\FilesystemOperator|\PHPUnit\Framework\MockObject\MockObject */ - private FilesystemOperator $filesystem; + private FilesystemOperator & MockObject $filesystem; protected function setUp(): void { @@ -34,11 +33,12 @@ protected function setUp(): void public function testCreate(): void { $stream = fopen('php://memory', 'rb'); + self::assertNotFalse($stream, 'Failed to create in-memory stream'); $spiBinaryFileCreateStruct = new SPIBinaryFileCreateStruct(); $spiBinaryFileCreateStruct->id = 'prefix/my/file.png'; $spiBinaryFileCreateStruct->mimeType = 'image/png'; $spiBinaryFileCreateStruct->size = 123; - $spiBinaryFileCreateStruct->mtime = 1307155200; + $spiBinaryFileCreateStruct->mtime = new \DateTime('@1307155200'); $spiBinaryFileCreateStruct->setInputStream($stream); $this->filesystem diff --git a/tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php b/tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php index 149c49585f..beef55336e 100644 --- a/tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php +++ b/tests/lib/IO/IOMetadataHandler/LegacyDFSClusterTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Core\IO\IOMetadataHandler; @@ -14,25 +15,22 @@ use Doctrine\DBAL\Result; use Ibexa\Contracts\Core\IO\BinaryFile as SPIBinaryFile; use Ibexa\Contracts\Core\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct; -use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException; use Ibexa\Core\IO\Exception\BinaryFileNotFoundException; use Ibexa\Core\IO\IOMetadataHandler\LegacyDFSCluster; use Ibexa\Core\IO\UrlDecorator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class LegacyDFSClusterTest extends TestCase { - /** @var \Ibexa\Core\IO\IOMetadataHandler&\PHPUnit\Framework\MockObject\MockObject */ - private $handler; + private LegacyDFSCluster $handler; - /** @var \Doctrine\DBAL\Connection&\PHPUnit\Framework\MockObject\MockObject */ - private $dbalMock; + private Connection & MockObject $dbalMock; /** @var \Doctrine\DBAL\Query\QueryBuilder&\PHPUnit\Framework\MockObject\MockObject */ - private $qbMock; + private QueryBuilder & MockObject $qbMock; - /** @var \Ibexa\Core\IO\UrlDecorator&\PHPUnit\Framework\MockObject\MockObject */ - private $urlDecoratorMock; + private UrlDecorator&MockObject $urlDecoratorMock; protected function setUp(): void { @@ -81,26 +79,9 @@ public function testCreate(string $id, string $mimeType, int $size, \DateTime $m $spiBinary = $this->handler->create($spiCreateStruct); - self::assertInstanceOf(SPIBinaryFile::class, $spiBinary); self::assertEquals($mtimeExpected, $spiBinary->mtime); } - public function testCreateInvalidArgument(): void - { - $this->dbalMock - ->expects(self::never()) - ->method('insert'); - - $spiCreateStruct = new SPIBinaryFileCreateStruct(); - $spiCreateStruct->id = 'prefix/my/file.png'; - $spiCreateStruct->mimeType = 'image/png'; - $spiCreateStruct->size = 123; - $spiCreateStruct->mtime = 1307155242; // Invalid, should be a DateTime - - $this->expectException(InvalidArgumentException::class); - $this->handler->create($spiCreateStruct); - } - public function testDelete(): void { $this->dbalMock diff --git a/tests/lib/IO/IOServiceTest.php b/tests/lib/IO/IOServiceTest.php index bcff3d4c54..f77125690f 100644 --- a/tests/lib/IO/IOServiceTest.php +++ b/tests/lib/IO/IOServiceTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Core\IO; @@ -67,7 +68,6 @@ public function testNewBinaryCreateStructFromLocalFile(): BinaryFileCreateStruct $file ); - self::assertInstanceOf(BinaryFileCreateStruct::class, $binaryCreateStruct); self::assertNull($binaryCreateStruct->id); self::assertIsResource($binaryCreateStruct->inputStream); self::assertEquals(filesize(__FILE__), $binaryCreateStruct->size); @@ -90,6 +90,7 @@ public function testCreateBinaryFile(BinaryFileCreateStruct $createStruct): Bina $filesize = filesize(__FILE__); self::assertNotFalse($filesize); $spiBinaryFile->size = $filesize; + $spiBinaryFile->mtime = new \DateTime('now'); $this->binarydataHandlerMock ->expects(self::once()) @@ -113,7 +114,6 @@ static function ($subject) use ($id): bool { ->willReturn($spiBinaryFile); $binaryFile = $this->ioService->createBinaryFile($createStruct); - self::assertInstanceOf(BinaryFile::class, $binaryFile); self::assertEquals($createStruct->id, $binaryFile->id); self::assertEquals($createStruct->size, $binaryFile->size); @@ -128,6 +128,7 @@ public function testLoadBinaryFile(): BinaryFile $spiBinaryFile->id = $spiId; $spiBinaryFile->size = 12345; $spiBinaryFile->uri = $spiId; + $spiBinaryFile->mtime = new \DateTime('now'); $this->metadataHandlerMock ->expects(self::once()) @@ -152,6 +153,7 @@ public function testLoadBinaryFileNoMetadataUri(): BinaryFile $spiBinaryFile = new SPIBinaryFile(); $spiBinaryFile->id = $spiId; $spiBinaryFile->size = 12345; + $spiBinaryFile->mtime = new \DateTime('now'); $this->metadataHandlerMock ->expects(self::once()) @@ -164,7 +166,9 @@ public function testLoadBinaryFileNoMetadataUri(): BinaryFile $expectedBinaryFile = new BinaryFile( [ 'id' => $id, - 'size' => 12345, 'uri' => $prefixedId, 'mtime' => null, + 'size' => 12345, + 'uri' => $prefixedId, + 'mtime' => $spiBinaryFile->mtime, ] ); @@ -192,6 +196,7 @@ public function testLoadBinaryFileByUri(): BinaryFile $spiBinaryFile->id = $spiId; $spiBinaryFile->size = 12345; $spiBinaryFile->uri = $spiId; + $spiBinaryFile->mtime = new \DateTime('now'); $this->binarydataHandlerMock ->expects(self::once()) diff --git a/tests/lib/IO/MimeTypeDetector/FileInfoTest.php b/tests/lib/IO/MimeTypeDetector/FileInfoTest.php index 8bf1beac7b..78792f7a02 100644 --- a/tests/lib/IO/MimeTypeDetector/FileInfoTest.php +++ b/tests/lib/IO/MimeTypeDetector/FileInfoTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Core\IO\MimeTypeDetector; @@ -12,8 +13,7 @@ class FileInfoTest extends TestCase { - /** @var \Ibexa\Core\IO\MimeTypeDetector\FileInfo */ - protected $mimeTypeDetector; + protected MimeTypeDetector $mimeTypeDetector; protected function setUp(): void { @@ -25,23 +25,31 @@ protected function getFixture(): string return __DIR__ . '/../../_fixtures/squirrel-developers.jpg'; } - public function testGetFromPath() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public function testGetFromPath(): void { self::assertEquals( + 'image/jpeg', $this->mimeTypeDetector->getFromPath( $this->getFixture() - ), - 'image/jpeg' + ) ); } - public function testGetFromBuffer() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public function testGetFromBuffer(): void { + $buffer = file_get_contents($this->getFixture()); + self::assertNotFalse($buffer, 'Failed to read fixture'); self::assertEquals( + 'image/jpeg', $this->mimeTypeDetector->getFromBuffer( - file_get_contents($this->getFixture()) - ), - 'image/jpeg' + $buffer + ) ); } } diff --git a/tests/lib/Repository/Service/Mock/ValueStub.php b/tests/lib/Repository/Service/Mock/ValueStub.php index c889d0c2f5..88aee4e086 100644 --- a/tests/lib/Repository/Service/Mock/ValueStub.php +++ b/tests/lib/Repository/Service/Mock/ValueStub.php @@ -4,31 +4,24 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Core\Repository\Service\Mock; use Ibexa\Core\FieldType\Value as BaseValue; /** - * Value for TextLine field type. + * Value for the TextLine field type. */ class ValueStub extends BaseValue { - /** @var string */ - public $value; - - /** - * Construct a new Value object and initialize it $value. - * - * @param string $value - */ - public function __construct($value) + public function __construct(public readonly string $value) { - $this->value = $value; + parent::__construct(); } - public function __toString() + public function __toString(): string { - return (string)$this->value; + return $this->value; } }