diff --git a/composer.json b/composer.json index bde2512d0..9517609dd 100644 --- a/composer.json +++ b/composer.json @@ -50,9 +50,9 @@ "guzzlehttp/guzzle": "^7.8", "phpspec/prophecy-phpunit": "2.*", "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-doctrine": "^1.3.21", - "rector/rector": "^1.0", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-doctrine": "^2.0", + "rector/rector": "2.*", "symfony/browser-kit": "^7.0", "symfony/css-selector": "^7.0", "symfony/debug-bundle": "^7.0", diff --git a/composer.lock b/composer.lock index 9a3fc2708..47c54b824 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a56904fb204673b013f4f1d5823cc9ef", + "content-hash": "6ff625247af88831d3d1321187c206d2", "packages": [ { "name": "brick/math", @@ -451,29 +451,27 @@ }, { "name": "doctrine/deprecations", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/31610dbb31faa98e6b5447b62340826f54fbc4e9", + "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", - "phpstan/phpstan": "1.4.10 || 1.10.15", - "phpstan/phpstan-phpunit": "^1.0", + "doctrine/coding-standard": "^9 || ^12", + "phpstan/phpstan": "1.4.10 || 2.0.3", + "phpstan/phpstan-phpunit": "^1.0 || ^2", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "psalm/plugin-phpunit": "0.18.4", - "psr/log": "^1 || ^2 || ^3", - "vimeo/psalm": "4.30.0 || 5.12.0" + "psr/log": "^1 || ^2 || ^3" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -481,7 +479,7 @@ "type": "library", "autoload": { "psr-4": { - "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + "Doctrine\\Deprecations\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -492,9 +490,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + "source": "https://github.com/doctrine/deprecations/tree/1.1.4" }, - "time": "2024-01-30T19:34:25+00:00" + "time": "2024-12-07T21:18:45+00:00" }, { "name": "doctrine/doctrine-bundle", @@ -1526,16 +1524,16 @@ }, { "name": "monolog/monolog", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "32e515fdc02cdafbe4593e30a9350d486b125b67" + "reference": "aef6ee73a77a66e404dd6540934a9ef1b3c855b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/32e515fdc02cdafbe4593e30a9350d486b125b67", - "reference": "32e515fdc02cdafbe4593e30a9350d486b125b67", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/aef6ee73a77a66e404dd6540934a9ef1b3c855b4", + "reference": "aef6ee73a77a66e404dd6540934a9ef1b3c855b4", "shasum": "" }, "require": { @@ -1613,7 +1611,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/3.8.0" + "source": "https://github.com/Seldaek/monolog/tree/3.8.1" }, "funding": [ { @@ -1625,7 +1623,7 @@ "type": "tidelift" } ], - "time": "2024-11-12T13:57:08+00:00" + "time": "2024-12-05T17:15:07+00:00" }, { "name": "openpsa/universalfeedcreator", @@ -2309,16 +2307,16 @@ }, { "name": "symfony/cache", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "2c926bc348184b4b235f2200fcbe8fcf3c8c5b8a" + "reference": "e7e983596b744c4539f31e79b0350a6cf5878a20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/2c926bc348184b4b235f2200fcbe8fcf3c8c5b8a", - "reference": "2c926bc348184b4b235f2200fcbe8fcf3c8c5b8a", + "url": "https://api.github.com/repos/symfony/cache/zipball/e7e983596b744c4539f31e79b0350a6cf5878a20", + "reference": "e7e983596b744c4539f31e79b0350a6cf5878a20", "shasum": "" }, "require": { @@ -2387,7 +2385,7 @@ "psr6" ], "support": { - "source": "https://github.com/symfony/cache/tree/v7.2.0" + "source": "https://github.com/symfony/cache/tree/v7.2.1" }, "funding": [ { @@ -2403,7 +2401,7 @@ "type": "tidelift" } ], - "time": "2024-11-25T15:21:05+00:00" + "time": "2024-12-07T08:08:50+00:00" }, { "name": "symfony/cache-contracts", @@ -2632,16 +2630,16 @@ }, { "name": "symfony/console", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf" + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", + "url": "https://api.github.com/repos/symfony/console/zipball/fefcc18c0f5d0efe3ab3152f15857298868dc2c3", + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3", "shasum": "" }, "require": { @@ -2705,7 +2703,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.2.0" + "source": "https://github.com/symfony/console/tree/v7.2.1" }, "funding": [ { @@ -2721,7 +2719,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T14:24:19+00:00" + "time": "2024-12-11T03:49:26+00:00" }, { "name": "symfony/css-selector", @@ -2937,16 +2935,16 @@ }, { "name": "symfony/doctrine-bridge", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/doctrine-bridge.git", - "reference": "09dbb7c731430335e9ae89ee5054b5f5580c49bf" + "reference": "b492be51eb703723d682851a0c9fb39b9d1a7bfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/doctrine-bridge/zipball/09dbb7c731430335e9ae89ee5054b5f5580c49bf", - "reference": "09dbb7c731430335e9ae89ee5054b5f5580c49bf", + "url": "https://api.github.com/repos/symfony/doctrine-bridge/zipball/b492be51eb703723d682851a0c9fb39b9d1a7bfb", + "reference": "b492be51eb703723d682851a0c9fb39b9d1a7bfb", "shasum": "" }, "require": { @@ -3026,7 +3024,7 @@ "description": "Provides integration for Doctrine with various Symfony components", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/doctrine-bridge/tree/v7.2.0" + "source": "https://github.com/symfony/doctrine-bridge/tree/v7.2.1" }, "funding": [ { @@ -3042,7 +3040,7 @@ "type": "tidelift" } ], - "time": "2024-11-25T12:10:02+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/dotenv", @@ -3120,16 +3118,16 @@ }, { "name": "symfony/error-handler", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "672b3dd1ef8b87119b446d67c58c106c43f965fe" + "reference": "6150b89186573046167796fa5f3f76601d5145f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/672b3dd1ef8b87119b446d67c58c106c43f965fe", - "reference": "672b3dd1ef8b87119b446d67c58c106c43f965fe", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/6150b89186573046167796fa5f3f76601d5145f8", + "reference": "6150b89186573046167796fa5f3f76601d5145f8", "shasum": "" }, "require": { @@ -3175,7 +3173,7 @@ "description": "Provides tools to manage errors and ease debugging PHP code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/error-handler/tree/v7.2.0" + "source": "https://github.com/symfony/error-handler/tree/v7.2.1" }, "funding": [ { @@ -3191,7 +3189,7 @@ "type": "tidelift" } ], - "time": "2024-11-05T15:35:02+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/event-dispatcher", @@ -3646,16 +3644,16 @@ }, { "name": "symfony/framework-bundle", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/framework-bundle.git", - "reference": "a8d0da4110fe643ab3cde7c938a03e222fe787c6" + "reference": "1c630f4697c9bd87b342e8090cc9022071af4d77" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/framework-bundle/zipball/a8d0da4110fe643ab3cde7c938a03e222fe787c6", - "reference": "a8d0da4110fe643ab3cde7c938a03e222fe787c6", + "url": "https://api.github.com/repos/symfony/framework-bundle/zipball/1c630f4697c9bd87b342e8090cc9022071af4d77", + "reference": "1c630f4697c9bd87b342e8090cc9022071af4d77", "shasum": "" }, "require": { @@ -3776,7 +3774,7 @@ "description": "Provides a tight integration between Symfony components and the Symfony full-stack framework", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/framework-bundle/tree/v7.2.0" + "source": "https://github.com/symfony/framework-bundle/tree/v7.2.1" }, "funding": [ { @@ -3792,27 +3790,27 @@ "type": "tidelift" } ], - "time": "2024-11-20T16:27:35+00:00" + "time": "2024-12-07T13:24:01+00:00" }, { "name": "symfony/http-client", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "955e43336aff03df1e8a8e17daefabb0127a313b" + "reference": "ff4df2b68d1c67abb9fef146e6540ea16b58d99e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/955e43336aff03df1e8a8e17daefabb0127a313b", - "reference": "955e43336aff03df1e8a8e17daefabb0127a313b", + "url": "https://api.github.com/repos/symfony/http-client/zipball/ff4df2b68d1c67abb9fef146e6540ea16b58d99e", + "reference": "ff4df2b68d1c67abb9fef146e6540ea16b58d99e", "shasum": "" }, "require": { "php": ">=8.2", "psr/log": "^1|^2|^3", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/http-client-contracts": "~3.4.3|^3.5.1", + "symfony/http-client-contracts": "~3.4.4|^3.5.2", "symfony/service-contracts": "^2.5|^3" }, "conflict": { @@ -3871,7 +3869,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.2.0" + "source": "https://github.com/symfony/http-client/tree/v7.2.1" }, "funding": [ { @@ -3887,20 +3885,20 @@ "type": "tidelift" } ], - "time": "2024-11-29T08:22:02+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/http-client-contracts", - "version": "v3.5.1", + "version": "v3.5.2", "source": { "type": "git", "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "c2f3ad828596624ca39ea40f83617ef51ca8bbf9" + "reference": "ee8d807ab20fcb51267fdace50fbe3494c31e645" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/c2f3ad828596624ca39ea40f83617ef51ca8bbf9", - "reference": "c2f3ad828596624ca39ea40f83617ef51ca8bbf9", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/ee8d807ab20fcb51267fdace50fbe3494c31e645", + "reference": "ee8d807ab20fcb51267fdace50fbe3494c31e645", "shasum": "" }, "require": { @@ -3908,12 +3906,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -3949,7 +3947,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.2" }, "funding": [ { @@ -3965,7 +3963,7 @@ "type": "tidelift" } ], - "time": "2024-11-25T12:02:18+00:00" + "time": "2024-12-07T08:49:48+00:00" }, { "name": "symfony/http-foundation", @@ -4047,16 +4045,16 @@ }, { "name": "symfony/http-kernel", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d" + "reference": "d8ae58eecae44c8e66833e76cc50a4ad3c002d97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d", - "reference": "6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/d8ae58eecae44c8e66833e76cc50a4ad3c002d97", + "reference": "d8ae58eecae44c8e66833e76cc50a4ad3c002d97", "shasum": "" }, "require": { @@ -4141,7 +4139,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.2.0" + "source": "https://github.com/symfony/http-kernel/tree/v7.2.1" }, "funding": [ { @@ -4157,7 +4155,7 @@ "type": "tidelift" } ], - "time": "2024-11-29T08:42:40+00:00" + "time": "2024-12-11T12:09:10+00:00" }, { "name": "symfony/intl", @@ -4327,16 +4325,16 @@ }, { "name": "symfony/mime", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d" + "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/cc84a4b81f62158c3846ac7ff10f696aae2b524d", - "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d", + "url": "https://api.github.com/repos/symfony/mime/zipball/7f9617fcf15cb61be30f8b252695ed5e2bfac283", + "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283", "shasum": "" }, "require": { @@ -4391,7 +4389,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v7.2.0" + "source": "https://github.com/symfony/mime/tree/v7.2.1" }, "funding": [ { @@ -4407,7 +4405,7 @@ "type": "tidelift" } ], - "time": "2024-11-23T09:19:39+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/monolog-bridge", @@ -4733,8 +4731,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4809,8 +4807,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4972,8 +4970,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5054,8 +5052,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5138,8 +5136,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5212,8 +5210,8 @@ "type": "metapackage", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "notification-url": "https://packagist.org/downloads/", @@ -5277,8 +5275,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5357,8 +5355,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5433,8 +5431,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5567,16 +5565,16 @@ }, { "name": "symfony/property-info", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/property-info.git", - "reference": "b00580d9d7c9654e1df95df85105d0da67418b3f" + "reference": "65fb9be15380f949d72ff405473cce733364b8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/property-info/zipball/b00580d9d7c9654e1df95df85105d0da67418b3f", - "reference": "b00580d9d7c9654e1df95df85105d0da67418b3f", + "url": "https://api.github.com/repos/symfony/property-info/zipball/65fb9be15380f949d72ff405473cce733364b8b4", + "reference": "65fb9be15380f949d72ff405473cce733364b8b4", "shasum": "" }, "require": { @@ -5630,7 +5628,7 @@ "validator" ], "support": { - "source": "https://github.com/symfony/property-info/tree/v7.2.0" + "source": "https://github.com/symfony/property-info/tree/v7.2.1" }, "funding": [ { @@ -5646,7 +5644,7 @@ "type": "tidelift" } ], - "time": "2024-11-27T09:50:52+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/routing", @@ -6073,16 +6071,16 @@ }, { "name": "symfony/security-http", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/security-http.git", - "reference": "0d0ab4d491f22306c893b2d30ce73ea911201a61" + "reference": "125844598d9cef4fe72a9f6c4a78ac7c59c3f532" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/security-http/zipball/0d0ab4d491f22306c893b2d30ce73ea911201a61", - "reference": "0d0ab4d491f22306c893b2d30ce73ea911201a61", + "url": "https://api.github.com/repos/symfony/security-http/zipball/125844598d9cef4fe72a9f6c4a78ac7c59c3f532", + "reference": "125844598d9cef4fe72a9f6c4a78ac7c59c3f532", "shasum": "" }, "require": { @@ -6141,7 +6139,7 @@ "description": "Symfony Security Component - HTTP Integration", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/security-http/tree/v7.2.0" + "source": "https://github.com/symfony/security-http/tree/v7.2.1" }, "funding": [ { @@ -6157,7 +6155,7 @@ "type": "tidelift" } ], - "time": "2024-11-13T13:40:36+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/service-contracts", @@ -6566,16 +6564,16 @@ }, { "name": "symfony/twig-bridge", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/twig-bridge.git", - "reference": "9958f5a5b6640734fe4b24c18897191f77a02c61" + "reference": "d5cdf4d59da5ab44ebd7503480c22d8235887de0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/twig-bridge/zipball/9958f5a5b6640734fe4b24c18897191f77a02c61", - "reference": "9958f5a5b6640734fe4b24c18897191f77a02c61", + "url": "https://api.github.com/repos/symfony/twig-bridge/zipball/d5cdf4d59da5ab44ebd7503480c22d8235887de0", + "reference": "d5cdf4d59da5ab44ebd7503480c22d8235887de0", "shasum": "" }, "require": { @@ -6656,7 +6654,7 @@ "description": "Provides integration for Twig with various Symfony components", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/twig-bridge/tree/v7.2.0" + "source": "https://github.com/symfony/twig-bridge/tree/v7.2.1" }, "funding": [ { @@ -6672,7 +6670,7 @@ "type": "tidelift" } ], - "time": "2024-11-25T14:26:33+00:00" + "time": "2024-12-07T09:50:32+00:00" }, { "name": "symfony/twig-bundle", @@ -6760,29 +6758,24 @@ }, { "name": "symfony/type-info", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/type-info.git", - "reference": "e0bfd95bceb3886c59487828537691aecb7d9c6b" + "reference": "4f402070b08ad0b87e9cadbb07b87fb36061e6e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/type-info/zipball/e0bfd95bceb3886c59487828537691aecb7d9c6b", - "reference": "e0bfd95bceb3886c59487828537691aecb7d9c6b", + "url": "https://api.github.com/repos/symfony/type-info/zipball/4f402070b08ad0b87e9cadbb07b87fb36061e6e4", + "reference": "4f402070b08ad0b87e9cadbb07b87fb36061e6e4", "shasum": "" }, "require": { "php": ">=8.2", "psr/container": "^1.1|^2.0" }, - "conflict": { - "phpstan/phpdoc-parser": "<1.0", - "symfony/dependency-injection": "<6.4" - }, "require-dev": { - "phpstan/phpdoc-parser": "^1.0|^2.0", - "symfony/dependency-injection": "^6.4|^7.0" + "phpstan/phpdoc-parser": "^1.0|^2.0" }, "type": "library", "autoload": { @@ -6820,7 +6813,7 @@ "type" ], "support": { - "source": "https://github.com/symfony/type-info/tree/v7.2.0" + "source": "https://github.com/symfony/type-info/tree/v7.2.1" }, "funding": [ { @@ -6836,7 +6829,7 @@ "type": "tidelift" } ], - "time": "2024-11-18T09:51:31+00:00" + "time": "2024-12-11T07:49:41+00:00" }, { "name": "symfony/validator", @@ -7221,7 +7214,7 @@ }, { "name": "twig/cssinliner-extra", - "version": "v3.16.0", + "version": "v3.17.0", "source": { "type": "git", "url": "https://github.com/twigphp/cssinliner-extra.git", @@ -7274,7 +7267,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/cssinliner-extra/tree/v3.16.0" + "source": "https://github.com/twigphp/cssinliner-extra/tree/v3.17.0" }, "funding": [ { @@ -7290,7 +7283,7 @@ }, { "name": "twig/extra-bundle", - "version": "v3.16.0", + "version": "v3.17.0", "source": { "type": "git", "url": "https://github.com/twigphp/twig-extra-bundle.git", @@ -7348,7 +7341,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/twig-extra-bundle/tree/v3.16.0" + "source": "https://github.com/twigphp/twig-extra-bundle/tree/v3.17.0" }, "funding": [ { @@ -7364,7 +7357,7 @@ }, { "name": "twig/intl-extra", - "version": "v3.16.0", + "version": "v3.17.0", "source": { "type": "git", "url": "https://github.com/twigphp/intl-extra.git", @@ -7412,7 +7405,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/intl-extra/tree/v3.16.0" + "source": "https://github.com/twigphp/intl-extra/tree/v3.17.0" }, "funding": [ { @@ -7428,16 +7421,16 @@ }, { "name": "twig/twig", - "version": "v3.16.0", + "version": "v3.17.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561" + "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/475ad2dc97d65d8631393e721e7e44fb544f0561", - "reference": "475ad2dc97d65d8631393e721e7e44fb544f0561", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71", + "reference": "677ef8da6497a03048192aeeb5aa3018e379ac71", "shasum": "" }, "require": { @@ -7492,7 +7485,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.16.0" + "source": "https://github.com/twigphp/Twig/tree/v3.17.1" }, "funding": [ { @@ -7504,7 +7497,7 @@ "type": "tidelift" } ], - "time": "2024-11-29T08:27:05+00:00" + "time": "2024-12-12T09:58:10+00:00" } ], "packages-dev": [ @@ -7598,25 +7591,25 @@ }, { "name": "behat/gherkin", - "version": "v4.10.0", + "version": "v4.11.0", "source": { "type": "git", "url": "https://github.com/Behat/Gherkin.git", - "reference": "cbb83c4c435dd8d05a161f2a5ae322e61b2f4db6" + "reference": "32821a17b12620951e755b5d49328a6421a5b5b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Behat/Gherkin/zipball/cbb83c4c435dd8d05a161f2a5ae322e61b2f4db6", - "reference": "cbb83c4c435dd8d05a161f2a5ae322e61b2f4db6", + "url": "https://api.github.com/repos/Behat/Gherkin/zipball/32821a17b12620951e755b5d49328a6421a5b5b5", + "reference": "32821a17b12620951e755b5d49328a6421a5b5b5", "shasum": "" }, "require": { - "php": "~7.2|~8.0" + "php": "8.1.* || 8.2.* || 8.3.* || 8.4.*" }, "require-dev": { "cucumber/cucumber": "dev-gherkin-24.1.0", - "phpunit/phpunit": "~8|~9", - "symfony/yaml": "~3|~4|~5|~6|~7" + "phpunit/phpunit": "^9.6", + "symfony/yaml": "^5.4 || ^6.4 || ^7.0" }, "suggest": { "symfony/yaml": "If you want to parse features, represented in YAML files" @@ -7655,9 +7648,9 @@ ], "support": { "issues": "https://github.com/Behat/Gherkin/issues", - "source": "https://github.com/Behat/Gherkin/tree/v4.10.0" + "source": "https://github.com/Behat/Gherkin/tree/v4.11.0" }, - "time": "2024-10-19T14:46:06+00:00" + "time": "2024-12-06T10:07:25+00:00" }, { "name": "behat/mink", @@ -9160,16 +9153,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.6.0", + "version": "5.6.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c" + "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/f3558a4c23426d12bffeaab463f8a8d8b681193c", - "reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", + "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", "shasum": "" }, "require": { @@ -9218,9 +9211,9 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.1" }, - "time": "2024-11-12T11:25:25+00:00" + "time": "2024-12-07T09:39:29+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -9502,20 +9495,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.12", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0" + "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46b4d3529b12178112d9008337beda0cc2a1a6b4", + "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -9556,25 +9549,25 @@ "type": "github" } ], - "time": "2024-11-28T22:13:23+00:00" + "time": "2024-11-28T22:19:37+00:00" }, { "name": "phpstan/phpstan-doctrine", - "version": "1.5.7", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "231d3f795ed5ef54c98961fd3958868cbe091207" + "reference": "bdb6a835c5aa9725979694ae9b70591e180f4853" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/231d3f795ed5ef54c98961fd3958868cbe091207", - "reference": "231d3f795ed5ef54c98961fd3958868cbe091207", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/bdb6a835c5aa9725979694ae9b70591e180f4853", + "reference": "bdb6a835c5aa9725979694ae9b70591e180f4853", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0.3" }, "conflict": { "doctrine/collections": "<1.0", @@ -9587,20 +9580,19 @@ "cache/array-adapter": "^1.1", "composer/semver": "^3.3.2", "cweagans/composer-patches": "^1.7.3", - "doctrine/annotations": "^1.11 || ^2.0", + "doctrine/annotations": "^2.0", "doctrine/collections": "^1.6 || ^2.1", "doctrine/common": "^2.7 || ^3.0", - "doctrine/dbal": "^2.13.8 || ^3.3.3", + "doctrine/dbal": "^3.3.8", "doctrine/lexer": "^2.0 || ^3.0", - "doctrine/mongodb-odm": "^1.3 || ^2.4.3", + "doctrine/mongodb-odm": "^2.4.3", "doctrine/orm": "^2.16.0", "doctrine/persistence": "^2.2.1 || ^3.2", "gedmo/doctrine-extensions": "^3.8", "nesbot/carbon": "^2.49", - "nikic/php-parser": "^4.13.2", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.3.13", - "phpstan/phpstan-strict-rules": "^1.5.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^9.6.20", "ramsey/uuid": "^4.2", "symfony/cache": "^5.4" @@ -9626,22 +9618,22 @@ "description": "Doctrine extensions for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.7" + "source": "https://github.com/phpstan/phpstan-doctrine/tree/2.0.1" }, - "time": "2024-12-02T16:47:26+00:00" + "time": "2024-12-02T16:48:00+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "11.0.7", + "version": "11.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca" + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7f08030e8811582cc459871d28d6f5a1a4d35ca", - "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/418c59fd080954f8c4aa5631d9502ecda2387118", + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118", "shasum": "" }, "require": { @@ -9660,7 +9652,7 @@ "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^11.4.1" + "phpunit/phpunit": "^11.5.0" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -9698,7 +9690,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.7" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.8" }, "funding": [ { @@ -9706,7 +9698,7 @@ "type": "github" } ], - "time": "2024-10-09T06:21:38+00:00" + "time": "2024-12-11T12:34:27+00:00" }, { "name": "phpunit/php-file-iterator", @@ -9955,16 +9947,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.4.4", + "version": "11.5.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f9ba7bd3c9f3ff54ec379d7a1c2e3f13fe0bbde4" + "reference": "2b94d4f2450b9869fa64a46fd8a6a41997aef56a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f9ba7bd3c9f3ff54ec379d7a1c2e3f13fe0bbde4", - "reference": "f9ba7bd3c9f3ff54ec379d7a1c2e3f13fe0bbde4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2b94d4f2450b9869fa64a46fd8a6a41997aef56a", + "reference": "2b94d4f2450b9869fa64a46fd8a6a41997aef56a", "shasum": "" }, "require": { @@ -9988,11 +9980,12 @@ "sebastian/comparator": "^6.2.1", "sebastian/diff": "^6.0.2", "sebastian/environment": "^7.2.0", - "sebastian/exporter": "^6.1.3", + "sebastian/exporter": "^6.3.0", "sebastian/global-state": "^7.0.2", "sebastian/object-enumerator": "^6.0.1", "sebastian/type": "^5.1.0", - "sebastian/version": "^5.0.2" + "sebastian/version": "^5.0.2", + "staabm/side-effects-detector": "^1.0.5" }, "suggest": { "ext-soap": "To be able to generate mocks based on WSDL files" @@ -10003,7 +9996,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "11.4-dev" + "dev-main": "11.5-dev" } }, "autoload": { @@ -10035,7 +10028,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.4.4" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.1" }, "funding": [ { @@ -10051,7 +10044,7 @@ "type": "tidelift" } ], - "time": "2024-11-27T10:44:52+00:00" + "time": "2024-12-11T10:52:48+00:00" }, { "name": "psr/http-client", @@ -10789,21 +10782,21 @@ }, { "name": "rector/rector", - "version": "1.2.10", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61" + "reference": "3f27091368bd935dbbaa8387099792fb20f65f68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/3f27091368bd935dbbaa8387099792fb20f65f68", + "reference": "3f27091368bd935dbbaa8387099792fb20f65f68", "shasum": "" }, "require": { - "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.12.5" + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.0.1" }, "conflict": { "rector/rector-doctrine": "*", @@ -10836,7 +10829,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/1.2.10" + "source": "https://github.com/rectorphp/rector/tree/2.0.3" }, "funding": [ { @@ -10844,7 +10837,7 @@ "type": "github" } ], - "time": "2024-11-08T13:59:10+00:00" + "time": "2024-12-12T15:22:19+00:00" }, { "name": "sebastian/cli-parser", @@ -10905,23 +10898,23 @@ }, { "name": "sebastian/code-unit", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "6bb7d09d6623567178cf54126afa9c2310114268" + "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268", - "reference": "6bb7d09d6623567178cf54126afa9c2310114268", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca", + "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.5" }, "type": "library", "extra": { @@ -10950,7 +10943,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/code-unit/issues", "security": "https://github.com/sebastianbergmann/code-unit/security/policy", - "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1" + "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.2" }, "funding": [ { @@ -10958,7 +10951,7 @@ "type": "github" } ], - "time": "2024-07-03T04:44:28+00:00" + "time": "2024-12-12T09:59:06+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -11284,16 +11277,16 @@ }, { "name": "sebastian/exporter", - "version": "6.1.3", + "version": "6.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e" + "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", - "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/3473f61172093b2da7de1fb5782e1f24cc036dc3", + "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3", "shasum": "" }, "require": { @@ -11302,7 +11295,7 @@ "sebastian/recursion-context": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^11.2" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { @@ -11350,7 +11343,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", "security": "https://github.com/sebastianbergmann/exporter/security/policy", - "source": "https://github.com/sebastianbergmann/exporter/tree/6.1.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/6.3.0" }, "funding": [ { @@ -11358,7 +11351,7 @@ "type": "github" } ], - "time": "2024-07-03T04:56:19+00:00" + "time": "2024-12-05T09:17:50+00:00" }, { "name": "sebastian/global-state", @@ -11769,6 +11762,58 @@ ], "time": "2024-10-09T05:16:32+00:00" }, + { + "name": "staabm/side-effects-detector", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/staabm/side-effects-detector.git", + "reference": "d8334211a140ce329c13726d4a715adbddd0a163" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163", + "reference": "d8334211a140ce329c13726d4a715adbddd0a163", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^1.12.6", + "phpunit/phpunit": "^9.6.21", + "symfony/var-dumper": "^5.4.43", + "tomasvotruba/type-coverage": "1.0.0", + "tomasvotruba/unused-public": "1.0.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A static analysis tool to detect side effects in PHP code", + "keywords": [ + "static analysis" + ], + "support": { + "issues": "https://github.com/staabm/side-effects-detector/issues", + "source": "https://github.com/staabm/side-effects-detector/tree/1.0.5" + }, + "funding": [ + { + "url": "https://github.com/staabm", + "type": "github" + } + ], + "time": "2024-10-20T05:08:20+00:00" + }, { "name": "symfony/browser-kit", "version": "v7.2.0", @@ -12406,12 +12451,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.2.0" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 358266633..3f109dfa7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,20 +1,12 @@ parameters: ignoreErrors: - # need refactoring - - message: '#Access to an undefined property object::\$template\.#' - path: src/Phyxo/MenuBar.php - - # need refactoring - - message: '#Access to an undefined property object::\$min_size\.#' - path: src/Phyxo/Image/ImageStandardParams.php - - # need refactoring - - message: '#Result of && is always false#' - path: src/DataMapper/AlbumMapper.php - - message: '#Empty array passed to foreach.#' path: src/Controller/Admin/AdminRatingController.php # No more ws functions ? - message: '#.*#' path: src/Phyxo/Functions/Ws/*.php + + # Not yet used + - message: '#Trait App\\Controller\\CommentControllerTrait is used zero times and is not analysed.#' + path: src/Controller/CommentControllerTrait.php diff --git a/rector.php b/rector.php index 73a17a274..4ca277c7c 100644 --- a/rector.php +++ b/rector.php @@ -24,14 +24,17 @@ __DIR__ . '/tests' ]) + ->withSkipPath(__DIR__ . '/src/Phyxo/Functions/Ws/') + ->withImportNames() + ->withAttributesSets(symfony: true, doctrine: true) + ->withSets([ DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, - SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, SymfonySetList::SYMFONY_CODE_QUALITY, SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, - LevelSetList::UP_TO_PHP_82, + LevelSetList::UP_TO_PHP_84, DoctrineSetList::DOCTRINE_CODE_QUALITY ]) @@ -42,7 +45,7 @@ ->withPreparedSets( deadCode: true, - // codeQuality: true, + codeQuality: true, // naming: true, - // privatization: true + privatization: true ); diff --git a/src/Command/AssetsInstallCommand.php b/src/Command/AssetsInstallCommand.php index 7a80d7ef6..b62fc904d 100644 --- a/src/Command/AssetsInstallCommand.php +++ b/src/Command/AssetsInstallCommand.php @@ -55,7 +55,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $targetArg = rtrim($input->getArgument('target') ?? '', '/'); - if (!$targetArg) { + if ($targetArg === '' || $targetArg === '0') { $targetArg = $this->rootProjectDir . '/public'; } @@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->newLine(); - if ($rows) { + if ($rows !== []) { $io->table(['', 'Theme', 'Method / Error'], $rows); } @@ -147,7 +147,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($copyUsed) { $io->note('Some assets were installed via copy. If you make changes to these assets you have to run this command again.'); } - $io->success($rows ? 'All assets were successfully installed.' : 'No assets were provided by any themes.'); + $io->success($rows !== [] ? 'All assets were successfully installed.' : 'No assets were provided by any themes.'); } return (int) $exitCode; diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index 3623595aa..111f022d6 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -130,10 +130,8 @@ public function execute(InputInterface $input, OutputInterface $output): int if (!empty($_SERVER['DATABASE_URL'])) { $this->db_params['dsn'] = $_SERVER['DATABASE_URL']; $this->db_params['db_prefix'] = $input->getOption('db_prefix') ?: $this->prefix; - } else { - if (!$io->askQuestion(new ConfirmationQuestion("Install Phyxo using these settings?", true))) { - return Command::SUCCESS; - } + } elseif (!$io->askQuestion(new ConfirmationQuestion("Install Phyxo using these settings?", true))) { + return Command::SUCCESS; } try { diff --git a/src/Controller/Admin/AdminAlbumController.php b/src/Controller/Admin/AdminAlbumController.php index b9668f5f2..68735ef52 100644 --- a/src/Controller/Admin/AdminAlbumController.php +++ b/src/Controller/Admin/AdminAlbumController.php @@ -41,7 +41,7 @@ class AdminAlbumController extends AbstractController { private TranslatorInterface $translator; - protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): TabSheet + protected function setTabsheet(int $album_id, string $section = 'properties', ?int $parent_id = null): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('properties', $this->translator->trans('Properties', [], 'admin'), $this->generateUrl('admin_album', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-pencil'); @@ -91,7 +91,7 @@ public function properties( } if ($conf['activate_comments']) { - $album->setCommentable($request->request->get('commentable') === 'true' ? true : false); + $album->setCommentable($request->request->get('commentable') === 'true'); $need_update = true; } @@ -221,7 +221,7 @@ public function sort_order( AlbumMapper $albumMapper, ImageStandardParams $image_std_params, TranslatorInterface $translator, - int $parent_id = null + ?int $parent_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -250,11 +250,12 @@ public function sort_order( $image_order_choice = $request->request->get('image_order_choice'); } - $image_order = null; + $image_order = ''; if ($image_order_choice === 'user_define') { for ($i = 0; $i < 3; $i++) { - if ($request->request->get('image_order')[$i]) { - if (!empty($image_order)) { + /** @phpstan-ignore-next-line */ + if ($request->request->get('image_order')[$i] !== '' && $request->request->get('image_order')[$i] !== '0') { + if ($image_order !== '') { $image_order .= ','; } $image_order .= $request->request->get('image_order')[$i]; @@ -330,11 +331,7 @@ public function sort_order( $image_order = explode(',', (string) $album->getImageOrder()); for ($i = 0; $i < 3; $i++) { // 3 fields - if (isset($image_order[$i])) { - $tpl_params['image_order'][] = $image_order[$i]; - } else { - $tpl_params['image_order'][] = ''; - } + $tpl_params['image_order'][] = $image_order[$i] ?? ''; } $tpl_params['image_order_choice'] = $image_order_choice; @@ -359,7 +356,7 @@ public function permissions( UserRepository $userRepository, GroupRepository $groupRepository, ManagerRegistry $managerRegistry, - int $parent_id = null + ?int $parent_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -447,7 +444,7 @@ public function permissions( } $user_granted_indirect_ids = []; - if (count($tpl_params['groups_selected']) > 0) { + if ($tpl_params['groups_selected'] !== []) { $granted_groups = []; foreach ($groupRepository->findBy(['id' => $tpl_params['groups_selected']]) as $group) { @@ -511,7 +508,7 @@ public function notification( GroupRepository $groupRepository, ImageMapper $imageMapper, TranslatorInterface $translator, - int $parent_id = null + ?int $parent_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -552,7 +549,7 @@ public function notification( $all_groups[$group->getId()] = $group->getName(); } - if (count($all_groups) === 0) { + if ($all_groups === []) { $tpl_params['no_group_in_gallery'] = true; } else { if ($album->getStatus() === Album::STATUS_PRIVATE) { @@ -561,14 +558,14 @@ public function notification( $group_ids[] = $group->getId(); } - if (count($group_ids) === 0) { + if ($group_ids === []) { $tpl_params['U_PERMISSIONS'] = $this->generateUrl('admin_album_permissions', ['album_id' => $album_id, 'parent_id' => $parent_id]); } } else { $group_ids = array_keys($all_groups); } - if (count($group_ids) > 0) { + if ($group_ids !== []) { $tpl_params['group_mail_options'] = array_filter($all_groups, fn ($key) => in_array($key, $group_ids), ARRAY_FILTER_USE_KEY); } } @@ -593,7 +590,7 @@ public function create( UserMapper $userMapper, UserInfosRepository $userInfosRepository, TranslatorInterface $translator, - int $parent_id = null + ?int $parent_id = null ): Response { if ($request->isMethod('POST')) { $album_name = $request->request->get('album_name'); @@ -625,7 +622,7 @@ public function create( return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]); } - public function delete(int $album_id, AlbumMapper $albumMapper, ImageMapper $imageMapper, UserMapper $userMapper, TranslatorInterface $translator, int $parent_id = null): Response + public function delete(int $album_id, AlbumMapper $albumMapper, ImageMapper $imageMapper, UserMapper $userMapper, TranslatorInterface $translator, ?int $parent_id = null): Response { $albumMapper->deleteAlbums([$album_id]); diff --git a/src/Controller/Admin/AdminAlbumsController.php b/src/Controller/Admin/AdminAlbumsController.php index 163b94e0c..4bac3051b 100644 --- a/src/Controller/Admin/AdminAlbumsController.php +++ b/src/Controller/Admin/AdminAlbumsController.php @@ -15,7 +15,6 @@ use App\Entity\Album; use App\Repository\AlbumRepository; use App\Repository\ImageAlbumRepository; -use Phyxo\Conf; use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -38,12 +37,11 @@ protected function setTabsheet(string $section = 'list'): TabSheet } public function list( - Conf $conf, AlbumRepository $albumRepository, CsrfTokenManagerInterface $csrfTokenManager, TranslatorInterface $translator, ImageAlbumRepository $imageAlbumRepository, - int $parent_id = null + ?int $parent_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -67,7 +65,7 @@ public function list( } // get the albums containing images directly - if (count($albums) > 0) { + if ($albums !== []) { $nb_photos_in = $imageAlbumRepository->countImagesByAlbum(); $all_albums = []; @@ -131,7 +129,7 @@ public function list( return $this->render('albums_list.html.twig', $tpl_params); } - public function update(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, int $parent_id = null): Response + public function update(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, ?int $parent_id = null): Response { if ($request->isMethod('POST')) { if ($request->request->get('submitManualOrder')) { // save manual category ordering @@ -162,15 +160,11 @@ public function update(Request $request, AlbumRepository $albumRepository, Album if (str_starts_with($order_by_field, 'date_')) { $order_by_date = true; - $ref_dates = $albumMapper->getAlbumsRefDate($category_ids, $order_by_field, 'ASC' == $order_by_asc ? 'min' : 'max'); + $ref_dates = $albumMapper->getAlbumsRefDate($category_ids, $order_by_field, 'ASC' === $order_by_asc ? 'min' : 'max'); } foreach ($albumRepository->findBy(['id' => $category_ids]) as $album) { - if ($order_by_date) { - $sort[] = $ref_dates[$album->getId()]; - } else { - $sort[] = $album->getName(); - } + $sort[] = $order_by_date ? $ref_dates[$album->getId()] : $album->getName(); $categories[] = [ 'id' => $album->getId(), @@ -178,7 +172,7 @@ public function update(Request $request, AlbumRepository $albumRepository, Album ]; } - array_multisort($sort, SORT_REGULAR, 'ASC' == $order_by_asc ? SORT_ASC : SORT_DESC, $categories); + array_multisort($sort, SORT_REGULAR, 'ASC' === $order_by_asc ? SORT_ASC : SORT_DESC, $categories); $albumMapper->saveAlbumsOrder($categories); $this->addFlash('success', $translator->trans('Albums automatically sorted', [], 'admin')); @@ -188,7 +182,7 @@ public function update(Request $request, AlbumRepository $albumRepository, Album return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]); } - public function move(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, int $parent_id = null): Response + public function move(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, ?int $parent_id = null): Response { $tpl_params = []; $this->translator = $translator; diff --git a/src/Controller/Admin/AdminBatchManagerController.php b/src/Controller/Admin/AdminBatchManagerController.php index 71127e04e..fdf2d0238 100644 --- a/src/Controller/Admin/AdminBatchManagerController.php +++ b/src/Controller/Admin/AdminBatchManagerController.php @@ -11,6 +11,7 @@ namespace App\Controller\Admin; +use DateTimeInterface; use DateTime; use App\DataMapper\AlbumMapper; use App\DataMapper\ImageMapper; @@ -69,7 +70,7 @@ protected function setTabsheet(string $section = 'global'): TabSheet protected function appendFilter(SessionInterface $session, array $filter = []): void { $previous_filter = $this->getFilter($session); - if (empty($previous_filter)) { + if ($previous_filter === []) { $previous_filter = []; } @@ -110,7 +111,7 @@ public function global( ManagerRegistry $managerRegistry, string $rootProjectDir, ImageLibraryGuesser $imageLibraryGuesser, - string $filter = null, + ?string $filter = null, int $start = 0 ): Response { $tpl_params = []; @@ -166,13 +167,10 @@ public function global( } } - if ($request->request->get('filter_level_use')) { - if (in_array($request->request->get('filter_level'), $conf['available_permission_levels'])) { - $this->appendFilter($request->getSession(), ['level' => $request->request->get('filter_level')]); - - if ($request->request->get('filter_level_include_lower')) { - $this->appendFilter($request->getSession(), ['level_include_lower' => true]); - } + if ($request->request->get('filter_level_use') && in_array($request->request->get('filter_level'), $conf['available_permission_levels'])) { + $this->appendFilter($request->getSession(), ['level' => $request->request->get('filter_level')]); + if ($request->request->get('filter_level_include_lower')) { + $this->appendFilter($request->getSession(), ['level_include_lower' => true]); } } @@ -309,7 +307,7 @@ public function global( } // creation date - $tpl_params['DATE_CREATION'] = !$request->request->get('date_creation') ? date('Y-m-d') . ' 00:00:00' : $request->request->get('date_creation'); + $tpl_params['DATE_CREATION'] = $request->request->get('date_creation') ?: date('Y-m-d') . ' 00:00:00'; // image level options $tpl_params['level_options'] = Utils::getPrivacyLevelOptions($translator, $conf['available_permission_levels'], 'admin'); @@ -332,12 +330,10 @@ public function global( $nb_images = (int) $request->get('display'); } $request->getSession()->set('unit_display', $nb_images); + } elseif ($request->getSession()->has('unit_display')) { + $nb_images = $request->getSession()->get('unit_display'); } else { - if ($request->getSession()->has('unit_display')) { - $nb_images = $request->getSession()->get('unit_display'); - } else { - $nb_images = 20; - } + $nb_images = 20; } $nb_thumbs_page = 0; @@ -468,7 +464,7 @@ protected function actionOnCollection( array $collection = [], ): ?Response { // if the user tries to apply an action, it means that there is at least 1 photo in the selection - if (count($collection) === 0 && !$request->request->get('submitFilter')) { + if ($collection === [] && !$request->request->get('submitFilter')) { $this->addFlash('error', $this->translator->trans('Select at least one photo', [], 'admin')); return null; } @@ -494,7 +490,7 @@ protected function actionOnCollection( if ($request->request->has('del_tags')) { $imageTagRepository->deleteByImagesAndTags($collection, $request->request->all('del_tags')); - if (!empty($this->getFilter($request->getSession())['tags']) && count(array_intersect($this->getFilter($request->getSession())['tags'], $request->request->all('del_tags'))) > 0) { + if (!empty($this->getFilter($request->getSession())['tags']) && array_intersect($this->getFilter($request->getSession())['tags'], $request->request->all('del_tags')) !== []) { $redirect = true; } } else { @@ -530,7 +526,7 @@ protected function actionOnCollection( $dissociables[] = $image->getId(); } - if (count($dissociables) > 0) { + if ($dissociables !== []) { $imageAlbumRepository->deleteByAlbum([$request->request->get('dissociate')], $dissociables); $this->addFlash('success', $this->translator->trans('Information data registered in database', [], 'admin')); @@ -538,20 +534,10 @@ protected function actionOnCollection( $redirect = true; } } elseif ($action === 'author') { - if ($request->request->get('remove_author')) { - $author = null; - } else { - $author = $request->request->get('author'); - } - + $author = $request->request->get('remove_author') ? null : $request->request->get('author'); $imageMapper->getRepository()->updateFieldForImages($collection, 'author', $author); } elseif ($action === 'title') { - if ($request->request->get('remove_title')) { - $title = null; - } else { - $title = $request->request->get('title'); - } - + $title = $request->request->get('remove_title') ? null : $request->request->get('title'); $imageMapper->getRepository()->updateFieldForImages($collection, 'name', $title); } elseif ($action === 'date_creation') { if ($request->request->get('remove_date_creation') || !$request->request->get('date_creation')) { @@ -564,10 +550,8 @@ protected function actionOnCollection( } elseif ($action === 'level') { // privacy_level $imageMapper->getRepository()->updateFieldForImages($collection, 'level', $request->request->get('level')); - if (!empty($this->getFilter($request->getSession())['level'])) { - if ($request->request->get('level') < $this->getFilter($request->getSession())['level']) { - $redirect = true; - } + if (!empty($this->getFilter($request->getSession())['level']) && $request->request->get('level') < $this->getFilter($request->getSession())['level']) { + $redirect = true; } } elseif ($action === 'add_to_caddie') { $userCaddies = $this->user->getCaddies(); @@ -669,7 +653,7 @@ protected function getFilterSetsFromFilter( break; case 'last_import': - if ($max_date_available = $imageMapper->getRepository()->findMaxDateAvailable()) { + if (($max_date_available = $imageMapper->getRepository()->findMaxDateAvailable()) instanceof DateTimeInterface) { $image_ids = []; foreach ($imageMapper->getRepository()->findImagesFromLastImport($max_date_available) as $image) { $image_ids[] = $image->getId(); @@ -870,7 +854,7 @@ protected function setDimensions(ImageMapper $imageMapper, SessionInterface $ses $filesizes[] = sprintf('%.1f', $image->getFilesize() / 1024); } - if (count($widths) === 0) { // arbitrary values, only used when no photos on the gallery + if ($widths === []) { // arbitrary values, only used when no photos on the gallery $widths = [600, 1920, 3500]; $heights = [480, 1080, 2300]; $ratios = [1.25, 1.52, 1.78]; @@ -909,9 +893,9 @@ protected function setDimensions(ImageMapper $imageMapper, SessionInterface $ses foreach ($ratios as $ratio) { if ($ratio < 0.95) { $ratio_categories['portrait'][] = $ratio; - } elseif ($ratio >= 0.95 and $ratio <= 1.05) { + } elseif ($ratio >= 0.95 && $ratio <= 1.05) { $ratio_categories['square'][] = $ratio; - } elseif ($ratio > 1.05 and $ratio < 2) { + } elseif ($ratio > 1.05 && $ratio < 2) { $ratio_categories['landscape'][] = $ratio; } elseif ($ratio >= 2) { $ratio_categories['panorama'][] = $ratio; @@ -919,7 +903,7 @@ protected function setDimensions(ImageMapper $imageMapper, SessionInterface $ses } foreach (array_keys($ratio_categories) as $type) { - if (count($ratio_categories[$type]) > 0) { + if ($ratio_categories[$type] !== []) { $dimensions['ratio_' . $type] = [ 'min' => $ratio_categories[$type][0], 'max' => end($ratio_categories[$type]), @@ -938,7 +922,7 @@ protected function setDimensions(ImageMapper $imageMapper, SessionInterface $ses $tpl_params['dimensions'] = $dimensions; - if (count($filesizes) === 0) { // arbitrary values, only used when no photos on the gallery + if ($filesizes === []) { // arbitrary values, only used when no photos on the gallery $filesizes = [0, 1, 2, 5, 8, 15]; } @@ -983,7 +967,7 @@ public function unit( FavoriteRepository $favoriteRepository, RouterInterface $router, ManagerRegistry $managerRegistry, - string $filter = null, + ?string $filter = null, int $start = 0 ): Response { $tpl_params = []; @@ -1082,7 +1066,7 @@ public function unit( } // creation date - $tpl_params['DATE_CREATION'] = !$request->request->get('date_creation') ? date('Y-m-d') . ' 00:00:00' : $request->request->get('date_creation'); + $tpl_params['DATE_CREATION'] = $request->request->get('date_creation') ?: date('Y-m-d') . ' 00:00:00'; // image level options $tpl_params['level_options'] = Utils::getPrivacyLevelOptions($translator, $conf['available_permission_levels'], 'admin'); @@ -1103,12 +1087,10 @@ public function unit( if ($request->get('display')) { $nb_images = (int) $request->get('display'); $request->getSession()->set('global_display', $nb_images); + } elseif ($request->getSession()->has('global_display')) { + $nb_images = $request->getSession()->get('global_display'); } else { - if ($request->getSession()->has('global_display')) { - $nb_images = $request->getSession()->get('global_display'); - } else { - $nb_images = 5; - } + $nb_images = 5; } if ((is_countable($current_set) ? count($current_set) : 0) > 0) { $tpl_params['navbar'] = Utils::createNavigationBar($router, 'admin_batch_manager_unit', ['filter' => $filter], is_countable($current_set) ? count($current_set) : 0, $start, $nb_images); diff --git a/src/Controller/Admin/AdminCommentsController.php b/src/Controller/Admin/AdminCommentsController.php index 24e84bdce..dd99928b9 100644 --- a/src/Controller/Admin/AdminCommentsController.php +++ b/src/Controller/Admin/AdminCommentsController.php @@ -61,13 +61,9 @@ public function index( } } - foreach ($commentRepository->getCommentsOnImages($validated = $section === 'pending' ? false : true, $conf['comments_page_nb_comments'], $start) as $comment) { + foreach ($commentRepository->getCommentsOnImages($validated = $section !== 'pending', $conf['comments_page_nb_comments'], $start) as $comment) { $derivative = new DerivativeImage($comment->getImage(), $image_std_params->getByType(ImageStandardParams::IMG_THUMB), $image_std_params); - if (!is_null($comment->getUser())) { - $author_name = $comment->getUser()->getUsername(); - } else { - $author_name = $comment->getAuthor(); - } + $author_name = is_null($comment->getUser()) ? $comment->getAuthor() : $comment->getUser()->getUsername(); $tpl_params['comments'][] = [ 'U_PICTURE' => $this->generateUrl('admin_photo', ['image_id' => $comment->getImage()->getId()]), @@ -89,7 +85,7 @@ public function index( $router, 'admin_comments', ['section' => $section], - ('pending' == $section ? $nb_pending : $nb_total - $nb_pending), + ('pending' === $section ? $nb_pending : $nb_total - $nb_pending), $start, $conf['comments_page_nb_comments'] ); diff --git a/src/Controller/Admin/AdminConfigurationController.php b/src/Controller/Admin/AdminConfigurationController.php index cc18edb02..05738b8c8 100644 --- a/src/Controller/Admin/AdminConfigurationController.php +++ b/src/Controller/Admin/AdminConfigurationController.php @@ -259,16 +259,12 @@ protected function sizesConfiguration(Conf $conf, ImageStandardParams $image_std // derivatives = multiple size $enabled = $image_std_params->getDefinedTypeMap(); - if (!empty($conf['disabled_derivatives'])) { - $disabled = $conf['disabled_derivatives']; - } else { - $disabled = []; - } + $disabled = empty($conf['disabled_derivatives']) ? [] : $conf['disabled_derivatives']; foreach ($image_std_params->getAllTypes() as $type) { $tpl_var = []; - $tpl_var['must_square'] = ($type == ImageStandardParams::IMG_SQUARE ? true : false); - $tpl_var['must_enable'] = ($type == ImageStandardParams::IMG_SQUARE || $type == ImageStandardParams::IMG_THUMB || $type == $conf['derivative_default_size']) ? true : false; + $tpl_var['must_square'] = ($type == ImageStandardParams::IMG_SQUARE); + $tpl_var['must_enable'] = $type == ImageStandardParams::IMG_SQUARE || $type == ImageStandardParams::IMG_THUMB || $type == $conf['derivative_default_size']; if (!empty($enabled[$type])) { $params = $enabled[$type]; @@ -326,19 +322,19 @@ protected function watermarkConfiguration(Conf $conf, string $themesDir, string $wm = $image_std_params->getWatermark(); $position = 'custom'; - if ($wm->xpos == 0 and $wm->ypos == 0) { + if ($wm->xpos == 0 && $wm->ypos == 0) { $position = 'topleft'; } - if ($wm->xpos == 100 and $wm->ypos == 0) { + if ($wm->xpos == 100 && $wm->ypos == 0) { $position = 'topright'; } - if ($wm->xpos == 50 and $wm->ypos == 50) { + if ($wm->xpos == 50 && $wm->ypos == 50) { $position = 'middle'; } - if ($wm->xpos == 0 and $wm->ypos == 100) { + if ($wm->xpos == 0 && $wm->ypos == 100) { $position = 'bottomleft'; } - if ($wm->xpos == 100 and $wm->ypos == 100) { + if ($wm->xpos == 100 && $wm->ypos == 100) { $position = 'bottomright'; } @@ -427,7 +423,7 @@ public function update( $order_by = $order_by_inside_category = array_slice($order_by, 0, (int) ceil(count($this->sort_fields) / 2)); // must define a default order_by if user want to order by rank only - if (count($order_by) === 0) { + if ($order_by === []) { $order_by = ['id', 'ASC']; } @@ -456,11 +452,9 @@ public function update( } } - if (($mail_theme = $request->request->get('mail_theme')) && isset($this->mail_themes[$mail_theme])) { - if ($conf['mail_theme'] !== $mail_theme) { - $conf_updated = true; - $conf['mail_theme'] = $mail_theme; - } + if (($mail_theme = $request->request->get('mail_theme')) && isset($this->mail_themes[$mail_theme]) && $conf['mail_theme'] !== $mail_theme) { + $conf_updated = true; + $conf['mail_theme'] = $mail_theme; } } elseif ($section === 'comments') { if ($request->request->get('nb_comment_page')) { @@ -606,10 +600,10 @@ public function update( $image_std_params->applyWatermark($params); $changed = $params->use_watermark != $old_use_watermark; - if (!$changed and $params->use_watermark) { + if (!$changed && $params->use_watermark) { $changed = $watermark_changed; } - if (!$changed and $params->use_watermark) { + if (!$changed && $params->use_watermark) { // if thresholds change and before/after the threshold is lower than the corresponding derivative side -> some derivatives might switch the watermark $changed |= $watermark_params->min_size[0] != $old_watermark->min_size[0] && ($watermark_params->min_size[0] < $params->max_width() || $old_watermark->min_size[0] < $params->max_width()); $changed |= $watermark_params->min_size[1] != $old_watermark->min_size[1] && ($watermark_params->min_size[1] < $params->max_height() || $old_watermark->min_size[1] < $params->max_height()); @@ -623,7 +617,7 @@ public function update( $image_std_params->save(); - if (count($changed_types)) { + if ($changed_types !== []) { $derivativeService->clearCache($changed_types, $image_std_params->getAllTypes()); } @@ -659,13 +653,13 @@ public function update( // step 1 - sanitize HTML input foreach ($pderivatives as $type => &$pderivative) { - if ($pderivative['must_square'] = ($type == ImageStandardParams::IMG_SQUARE ? true : false)) { + if ($pderivative['must_square'] = ($type == ImageStandardParams::IMG_SQUARE)) { $pderivative['h'] = $pderivative['w']; $pderivative['minh'] = $pderivative['minw'] = $pderivative['w']; $pderivative['crop'] = 100; } - $pderivative['must_enable'] = ($type == ImageStandardParams::IMG_SQUARE || $type == ImageStandardParams::IMG_THUMB || $type == $conf['derivative_default_size']) ? true : false; - $pderivative['enabled'] = isset($pderivative['enabled']) || $pderivative['must_enable'] ? true : false; + $pderivative['must_enable'] = $type == ImageStandardParams::IMG_SQUARE || $type == ImageStandardParams::IMG_THUMB || $type == $conf['derivative_default_size']; + $pderivative['enabled'] = isset($pderivative['enabled']) || $pderivative['must_enable']; if (isset($pderivative['crop'])) { $pderivative['crop'] = 100; @@ -702,33 +696,29 @@ public function update( } } else { $v = intval($pderivative['w']); - if ($v <= 0 or $v <= $prev_w) { + if ($v <= 0 || $v <= $prev_w) { $errors[$type]['w'] = '>' . $prev_w; } $v = intval($pderivative['h']); - if ($v <= 0 or $v <= $prev_h) { + if ($v <= 0 || $v <= $prev_h) { $errors[$type]['h'] = '>' . $prev_h; } } - if ((is_countable($errors) ? count($errors) : 0) == 0) { + if ($errors === []) { $prev_w = intval($pderivative['w']); $prev_h = intval($pderivative['h']); } } // step 3 - save data - if ((is_countable($errors) ? count($errors) : 0) == 0) { + if ($errors === []) { $quality_changed = $image_std_params->getQuality() != intval($request->request->get('resize_quality')); $image_std_params->setQuality(intval($request->request->get('resize_quality'))); $enabled = $image_std_params->getDefinedTypeMap(); - if (!empty($conf['disabled_derivatives'])) { - $disabled = $conf['disabled_derivatives']; - } else { - $disabled = []; - } + $disabled = empty($conf['disabled_derivatives']) ? [] : $conf['disabled_derivatives']; $changed_types = []; foreach ($image_std_params->getAllTypes() as $type) { @@ -741,9 +731,7 @@ public function update( [intval($pderivative['minw']), intval($pderivative['minh'])] ); $new_params = new DerivativeParams($derivative_params); - $image_std_params->applyWatermark($new_params); - if (isset($enabled[$type])) { $old_params = $enabled[$type]; $same = true; @@ -769,12 +757,12 @@ public function update( $enabled[$type] = $new_params; unset($disabled[$type]); } - } else { // disabled - if (isset($enabled[$type])) { // now disabled, before was enabled - $changed_types[] = $type; - $disabled[$type] = $enabled[$type]; - unset($enabled[$type]); - } + } elseif (isset($enabled[$type])) { + // disabled + // now disabled, before was enabled + $changed_types[] = $type; + $disabled[$type] = $enabled[$type]; + unset($enabled[$type]); } } @@ -799,7 +787,7 @@ public function update( $conf->addOrUpdateParam('disabled_derivatives', $disabled, 'base64'); } - if (count($changed_types)) { + if ($changed_types !== []) { $derivativeService->clearCache($changed_types, $image_std_params->getAllTypes()); } } diff --git a/src/Controller/Admin/AdminDashboardController.php b/src/Controller/Admin/AdminDashboardController.php index fdc7fe5e5..5c50d1dbf 100644 --- a/src/Controller/Admin/AdminDashboardController.php +++ b/src/Controller/Admin/AdminDashboardController.php @@ -118,11 +118,9 @@ public function index( $tpl_params['DB_COMMENTS'] = $translator->trans('number_of_comments', ['count' => $nb_comments], 'admin'); } - if ($nb_elements > 0) { - if ($min_date_available = $imageMapper->getRepository()->findMinDateAvailable()) { - $fmt = new IntlDateFormatter($request->get('_locale'), IntlDateFormatter::FULL, IntlDateFormatter::NONE); - $tpl_params['first_added'] = $translator->trans('first photo added on {date}', ['date' => $fmt->format($min_date_available)], 'admin'); - } + if ($nb_elements > 0 && $min_date_available = $imageMapper->getRepository()->findMinDateAvailable()) { + $fmt = new IntlDateFormatter($request->get('_locale'), IntlDateFormatter::FULL, IntlDateFormatter::NONE); + $tpl_params['first_added'] = $translator->trans('first photo added on {date}', ['date' => $fmt->format($min_date_available)], 'admin'); } $tpl_params['ws'] = $this->generateUrl('ws'); diff --git a/src/Controller/Admin/AdminGroupsController.php b/src/Controller/Admin/AdminGroupsController.php index 55c6d09e0..6d007f195 100644 --- a/src/Controller/Admin/AdminGroupsController.php +++ b/src/Controller/Admin/AdminGroupsController.php @@ -157,7 +157,7 @@ public function perm( public function action(Request $request, string $action, GroupRepository $groupRepository, TranslatorInterface $translator): Response { $group_selection = $request->request->all('group_selection'); - if (count($group_selection) === 0) { + if ($group_selection === []) { $this->addFlash('error', $translator->trans('Select at least one group', [], 'admin')); return $this->redirectToRoute('admin_groups'); diff --git a/src/Controller/Admin/AdminHistoryController.php b/src/Controller/Admin/AdminHistoryController.php index 2fb79129e..1c67781e7 100644 --- a/src/Controller/Admin/AdminHistoryController.php +++ b/src/Controller/Admin/AdminHistoryController.php @@ -64,9 +64,9 @@ public function stats( Conf $conf, HistorySummaryRepository $historySummaryRepository, HistoryRepository $historyRepository, - int $year = null, - int $month = null, - int $day = null + ?int $year = null, + ?int $month = null, + ?int $day = null ): Response { $tpl_params = []; $this->refreshSummary($historyRepository, $historySummaryRepository); @@ -126,7 +126,7 @@ public function stats( $min_x = min(array_keys($datas)); $max_x = max(array_keys($datas)); - if (count($datas) > 0) { + if ($datas !== []) { for ($i = $min_x; $i <= $max_x; $i++) { if (!isset($datas[$i])) { $datas[$i] = 0; @@ -176,7 +176,7 @@ public function search( TagRepository $tagRepository, HistoryRepository $historyRepository, RouterInterface $router, - int $search_id = null + ?int $search_id = null ): Response { $tpl_params = []; $search = null; @@ -307,10 +307,8 @@ protected function getElementFromSearchRules( $guest_id = $userMapper->getDefaultUser()->getId(); foreach ($history_lines as $line) { - if ($line->getImageType() && $line->getImageType() === 'high') { - if (isset($image_infos[$line->getImage()->getId()]['filesize'])) { - $summary['total_filesize'] += $image_infos[$line->getImage()->getId()]->getFilesize(); - } + if ($line->getImageType() && $line->getImageType() === 'high' && isset($image_infos[$line->getImage()->getId()]['filesize'])) { + $summary['total_filesize'] += $image_infos[$line->getImage()->getId()]->getFilesize(); } if ($line->getUser()->getId() === $guest_id) { @@ -357,7 +355,7 @@ protected function getElementFromSearchRules( } $summary['nb_guests'] = 0; - if (count(array_keys($summary['guests_ip'])) > 0) { + if (array_keys($summary['guests_ip']) !== []) { $summary['nb_guests'] = count(array_keys($summary['guests_ip'])); // we delete the "guest" from the $username_of hash so that it is avoided in next steps @@ -385,7 +383,7 @@ protected function getElementFromSearchRules( ]; } - protected function getImageString(ImageStandardParams $image_std_params, History $line, array $image_infos = [], SearchRulesModel $rules = null): string + protected function getImageString(ImageStandardParams $image_std_params, History $line, array $image_infos = [], ?SearchRulesModel $rules = null): string { $image_string = ''; diff --git a/src/Controller/Admin/AdminLanguagesController.php b/src/Controller/Admin/AdminLanguagesController.php index 6709c486b..0dbe6ddbe 100644 --- a/src/Controller/Admin/AdminLanguagesController.php +++ b/src/Controller/Admin/AdminLanguagesController.php @@ -101,7 +101,7 @@ public function installed( array_keys($languages->getFsLanguages()) ); - if (count($missing_language_ids) > 0) { + if ($missing_language_ids !== []) { $userInfosRepository->updateLanguageForLanguages($userMapper->getDefaultLanguage(), $missing_language_ids); } @@ -232,7 +232,7 @@ public function update( $server_languages = $languages->getServerLanguages($conf['pem_languages_category'], $params->get('core_version'), $new = false); $tpl_params['update_languages'] = []; - if (count($server_languages) > 0) { + if ($server_languages !== []) { foreach ($languages->getFsLanguages() as $extension_id => $fs_extension) { if (!isset($fs_extension['extension']) || !isset($server_languages[$fs_extension['extension']])) { continue; diff --git a/src/Controller/Admin/AdminMenubarController.php b/src/Controller/Admin/AdminMenubarController.php index 0d1fbb835..4dffa2d5f 100644 --- a/src/Controller/Admin/AdminMenubarController.php +++ b/src/Controller/Admin/AdminMenubarController.php @@ -29,11 +29,7 @@ public function index(Conf $conf, EventDispatcherInterface $eventDispatcher): Re { $tpl_params = []; - if (is_null($conf['blk_menubar'])) { - $mb_conf = []; - } else { - $mb_conf = $conf['blk_menubar']; - } + $mb_conf = is_null($conf['blk_menubar']) ? [] : $conf['blk_menubar']; $menu = new BlockManager('menubar'); $menu->loadDefaultBlocks(); @@ -67,11 +63,7 @@ public function update(Request $request, Conf $conf, EventDispatcherInterface $e $menu->loadRegisteredBlocks($eventDispatcher); $reg_blocks = $menu->getRegisteredBlocks(); - if (is_null($conf['blk_menubar'])) { - $mb_conf = []; - } else { - $mb_conf = $conf['blk_menubar']; - } + $mb_conf = is_null($conf['blk_menubar']) ? [] : $conf['blk_menubar']; foreach ($mb_conf as $id => $pos) { $hide = $request->request->get('hide_' . $id); @@ -95,7 +87,7 @@ private function makeConsecutive(array $blocks = [], array $orders = [], $step = uasort($orders, fn ($a, $b) => abs($a) - abs($b)); $idx = 1; - foreach ($blocks as $id => $block) { + foreach (array_keys($blocks) as $id) { if (!isset($orders[$id])) { $orders[$id] = $idx * 50; } diff --git a/src/Controller/Admin/AdminPhotoController.php b/src/Controller/Admin/AdminPhotoController.php index 9d4ccbcba..92b029078 100644 --- a/src/Controller/Admin/AdminPhotoController.php +++ b/src/Controller/Admin/AdminPhotoController.php @@ -69,7 +69,7 @@ public function edit( ImageAlbumRepository $imageAlbumRepository, RateRepository $rateRepository, ManagerRegistry $managerRegistry, - int $category_id = null + ?int $category_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -113,12 +113,12 @@ public function edit( // thumbnail for albums $no_longer_thumbnail_for = array_diff($represented_albums, $request->request->all('represent')); - if (count($no_longer_thumbnail_for) > 0) { + if ($no_longer_thumbnail_for !== []) { $albumMapper->setRandomRepresentant($no_longer_thumbnail_for); } $new_thumbnail_for = array_diff($request->request->all('represent'), $represented_albums); - if (count($new_thumbnail_for) > 0) { + if ($new_thumbnail_for !== []) { $albumMapper->getRepository()->updateAlbums(['representative_picture_id' => $image_id], $new_thumbnail_for); } @@ -221,14 +221,12 @@ public function edit( $url_img = ''; if ($category_id && in_array($category_id, $authorizeds)) { $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'album', 'element_id' => $category_id]); - } else { - if (count($authorizeds) > 0) { - $album_id = $authorizeds[0]; - $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'album', 'element_id' => $cache_albums[$album_id]->getId()]); - } + } elseif ($authorizeds !== []) { + $album_id = $authorizeds[0]; + $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'album', 'element_id' => $cache_albums[$album_id]->getId()]); } - if (!empty($url_img)) { + if ($url_img !== '' && $url_img !== '0') { $tpl_params['U_JUMPTO'] = $url_img; } @@ -254,7 +252,7 @@ public function delete( UserMapper $userMapper, ImageMapper $imageMapper, ImageAlbumRepository $imageAlbumRepository, - int $category_id = null + ?int $category_id = null ): Response { $imageMapper->deleteElements([$image_id], true); $userMapper->invalidateUserCache(); @@ -275,7 +273,7 @@ public function delete( $authorizeds = array_diff($image_albums, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()); - if (count($authorizeds) > 0) { + if ($authorizeds !== []) { return $this->redirectToRoute('admin_album', ['album_id' => $authorizeds[0]]); } @@ -284,7 +282,7 @@ public function delete( return $this->redirectToRoute('admin_home'); } - public function syncMetadata(int $image_id, AppUserService $appUserService, TagMapper $tagMapper, TranslatorInterface $translator, int $category_id = null): Response + public function syncMetadata(int $image_id, AppUserService $appUserService, TagMapper $tagMapper, TranslatorInterface $translator, ?int $category_id = null): Response { $tagMapper->sync_metadata([$image_id], $appUserService->getUser()); $this->addFlash('success', $translator->trans('Metadata synchronized from file', [], 'admin')); @@ -299,7 +297,7 @@ public function coi( ImageMapper $imageMapper, TranslatorInterface $translator, DerivativeService $derivativeService, - int $category_id = null + ?int $category_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -307,7 +305,7 @@ public function coi( $image = $imageMapper->getRepository()->find($image_id); if ($request->isMethod('POST')) { - if (strlen($request->request->get('l')) === 0) { + if ((string) $request->request->get('l') === '') { $image->setCoi(''); } else { $image->setCoi( @@ -372,7 +370,7 @@ public function rotate( ImageLibraryGuesser $imageLibraryGuesser, DerivativeService $derivativeService, string $rootProjectDir, - int $album_id = null, + ?int $album_id = null, ) { $tpl_params = []; $this->translator = $translator; diff --git a/src/Controller/Admin/AdminPhotosController.php b/src/Controller/Admin/AdminPhotosController.php index 865131794..954c92192 100644 --- a/src/Controller/Admin/AdminPhotosController.php +++ b/src/Controller/Admin/AdminPhotosController.php @@ -11,6 +11,7 @@ namespace App\Controller\Admin; +use App\Entity\Image; use App\DataMapper\AlbumMapper; use App\DataMapper\ImageMapper; use App\Entity\Caddie; @@ -48,7 +49,7 @@ public function direct( TranslatorInterface $translator, ImageMapper $imageMapper, ManagerRegistry $managerRegistry, - int $album_id = null + ?int $album_id = null ): Response { $tpl_params = []; $this->translator = $translator; @@ -108,12 +109,10 @@ public function direct( } } elseif ($request->getSession()->has('selected_category')) { $selected_category = json_decode((string) $request->getSession()->get('selected_category'), true, 512, JSON_THROW_ON_ERROR); - } else { + } elseif (($last_image = $imageMapper->getRepository()->findAlbumWithLastImageAdded()) instanceof Image) { // we need to know the category in which the last photo was added - if ($last_image = $imageMapper->getRepository()->findAlbumWithLastImageAdded()) { - if ($first_image_albums = $last_image->getImageAlbums()->first()) { - $selected_category = [$first_image_albums->getAlbum()->getId()]; - } + if ($first_image_albums = $last_image->getImageAlbums()->first()) { + $selected_category = [$first_image_albums->getAlbum()->getId()]; } } diff --git a/src/Controller/Admin/AdminRatingController.php b/src/Controller/Admin/AdminRatingController.php index 7ecd5896f..0c54431fe 100644 --- a/src/Controller/Admin/AdminRatingController.php +++ b/src/Controller/Admin/AdminRatingController.php @@ -100,8 +100,9 @@ public function photos( [$translator->trans('Creation date', [], 'admin'), 'date_creation DESC'], [$translator->trans('Post date', [], 'admin'), 'date_available DESC'], ]; + $counter = count($available_order_by); - for ($i = 0; $i < count($available_order_by); $i++) { + for ($i = 0; $i < $counter; $i++) { $tpl_params['order_by_options'][] = $available_order_by[$i][0]; } $tpl_params['order_by_options_selected'] = [$order_by_index]; @@ -221,11 +222,7 @@ public function users( $users_by_id[$rate->getUser()->getId()] = ['name' => '???' . $rate->getUser()->getId(), 'anon' => false]; } $usr = $users_by_id[$rate->getUser()->getId()]; - if ($usr['anon']) { - $user_key = $usr['name'] . '(' . $rate->getAnonymousId() . ')'; - } else { - $user_key = $usr['name']; - } + $user_key = $usr['anon'] ? $usr['name'] . '(' . $rate->getAnonymousId() . ')' : $usr['name']; $rating = &$by_user_ratings[$user_key]; if (is_null($rating)) { $rating = $by_user_rating_model; @@ -247,7 +244,7 @@ public function users( // get image tn urls $image_urls = []; - if (count($image_ids) > 0) { + if ($image_ids !== []) { $d_params = $image_std_params->getByType(ImageStandardParams::IMG_SQUARE); foreach ($imageMapper->getRepository()->findBy(['id' => array_keys($image_ids)]) as $image) { $derivative = new DerivativeImage($image, $d_params, $image_std_params); @@ -295,7 +292,7 @@ public function users( } $consensus_dev /= $c; - if ($consensus_dev_top_count) { + if ($consensus_dev_top_count !== 0) { $consensus_dev_top /= $consensus_dev_top_count; } @@ -306,7 +303,7 @@ public function users( 'avg' => $s / $c, 'cv' => $s == 0 ? -1 : sqrt($var) / ($s / $c), // http://en.wikipedia.org/wiki/Coefficient_of_variation 'cd' => $consensus_dev, - 'cdtop' => $consensus_dev_top_count ? $consensus_dev_top : '', + 'cdtop' => $consensus_dev_top_count !== 0 ? $consensus_dev_top : '', ]; } @@ -328,8 +325,9 @@ public function users( [$translator->trans('Consensus deviation', [], 'admin'), 'consensus_dev_compare'], [$translator->trans('Last', [], 'admin'), 'last_rate_compare'], ]; + $counter = count($available_order_by); - for ($i = 0; $i < count($available_order_by); $i++) { + for ($i = 0; $i < $counter; $i++) { $tpl_params['order_by_options'][] = $available_order_by[$i][0]; } diff --git a/src/Controller/Admin/AdminTagsController.php b/src/Controller/Admin/AdminTagsController.php index 2f1fa9df1..4aeaf0c7d 100644 --- a/src/Controller/Admin/AdminTagsController.php +++ b/src/Controller/Admin/AdminTagsController.php @@ -54,7 +54,7 @@ public function list( $orphan_tag_names[] = $tag->getName(); } - if (count($orphan_tag_names) > 0) { + if ($orphan_tag_names !== []) { $tpl_params['warnings'][] = sprintf( $translator->trans('You have %d orphan tags: %s.', [], 'admin') . ' ' . $translator->trans('Delete orphan tags', [], 'admin') . '', count($orphan_tag_names), diff --git a/src/Controller/Admin/AdminThemesController.php b/src/Controller/Admin/AdminThemesController.php index 252164adf..1a85999d5 100644 --- a/src/Controller/Admin/AdminThemesController.php +++ b/src/Controller/Admin/AdminThemesController.php @@ -254,21 +254,19 @@ public function action( $userInfosRepository->updateFieldForUsers('theme', $theme, $user_ids); } else { $error = $themes->performAction($action, $theme); - if ($action === 'activate') { - if (is_dir($originDir = $themesDir . '/' . $theme . '/build')) { - try { - $targetDir = $publicThemesDir . '/' . $theme; - $fs->remove($targetDir); - $directoryManager->relativeSymlinkWithFallback($originDir, $targetDir); - } catch (Exception $e) { - $error = 'Cannot copy web theme assets: ' . $e->getMessage(); - } + if ($action === 'activate' && is_dir($originDir = $themesDir . '/' . $theme . '/build')) { + try { + $targetDir = $publicThemesDir . '/' . $theme; + $fs->remove($targetDir); + $directoryManager->relativeSymlinkWithFallback($originDir, $targetDir); + } catch (Exception $e) { + $error = 'Cannot copy web theme assets: ' . $e->getMessage(); } } - } - if (!empty($error)) { - $this->addFlash('error', $error); + if ($error !== '' && $error !== '0') { + $this->addFlash('error', $error); + } } return $this->redirectToRoute('admin_themes_installed'); diff --git a/src/Controller/Admin/AdminUpdateController.php b/src/Controller/Admin/AdminUpdateController.php index 8680e4009..3066e7056 100644 --- a/src/Controller/Admin/AdminUpdateController.php +++ b/src/Controller/Admin/AdminUpdateController.php @@ -59,7 +59,7 @@ public function core( Plugins $plugins, Themes $themes, Languages $languages, - string $version = null, + ?string $version = null, int $step = 0 ): Response { $tpl_params = []; diff --git a/src/Controller/Admin/AdminUsersController.php b/src/Controller/Admin/AdminUsersController.php index 43f031733..f303bd281 100644 --- a/src/Controller/Admin/AdminUsersController.php +++ b/src/Controller/Admin/AdminUsersController.php @@ -77,7 +77,7 @@ public function list( } $tpl_params['users'] = $users; - $tpl_params['all_users'] = join(',', $user_ids); + $tpl_params['all_users'] = implode(',', $user_ids); $tpl_params['ACTIVATE_COMMENTS'] = $conf['activate_comments']; $tpl_params['Double_Password'] = $conf['double_password_type_in_admin']; diff --git a/src/Controller/AlbumController.php b/src/Controller/AlbumController.php index ca76dd356..f0c010099 100644 --- a/src/Controller/AlbumController.php +++ b/src/Controller/AlbumController.php @@ -183,7 +183,7 @@ public function album( $tpl_params['items'][] = $image->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); if (count($tpl_params['items']) > $nb_image_page) { @@ -246,7 +246,7 @@ public function albumFlat( $tpl_params['items'][] = $image['id']; } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); if (count($tpl_params['items']) > $nb_image_page) { @@ -300,7 +300,7 @@ public function albumsFlat( $tpl_params['items'][] = $image['id']; } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); if (count($tpl_params['items']) > $nb_image_page) { diff --git a/src/Controller/CommentControllerTrait.php b/src/Controller/CommentControllerTrait.php index 7b90c5f04..3b140e489 100644 --- a/src/Controller/CommentControllerTrait.php +++ b/src/Controller/CommentControllerTrait.php @@ -12,6 +12,7 @@ namespace App\Controller; use App\Form\DeleteCommentType; +use App\Form\EditCommentType; use App\Form\ValidateCommentType; use App\Repository\CommentRepository; use App\Security\AppUserService; diff --git a/src/Controller/FavoriteController.php b/src/Controller/FavoriteController.php index 95a07120e..33765be9a 100644 --- a/src/Controller/FavoriteController.php +++ b/src/Controller/FavoriteController.php @@ -50,7 +50,7 @@ public function index( $tpl_params['items'][] = $favorite->getImage()->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $tpl_params['favorite'] = ['U_FAVORITE' => $this->generateUrl('remove_all_favorites')]; $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); diff --git a/src/Controller/FeedController.php b/src/Controller/FeedController.php index 4ad9c057b..a897303fb 100644 --- a/src/Controller/FeedController.php +++ b/src/Controller/FeedController.php @@ -81,7 +81,7 @@ public function feed( $news = []; if (!$image_only) { $news = $notification->news($feed->getLastCheck(), $now, true, true); - if (count($news) > 0) { + if ($news !== []) { $item = new FeedItem(); $item->title = $translator->trans('New on {date}', ['date' => $now->format('Y-m-d H:m:i')]); $item->link = $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL); @@ -105,11 +105,10 @@ public function feed( } } - if (empty($news)) { // update the last check from time to time to avoid deletion by maintenance tasks - if (is_null($feed->getLastCheck()) || $now->diff($feed->getLastCheck())->format('s') > (30 * 24 * 3600)) { - $feed->setLastCheck($now->add(new DateInterval('P15D'))); - $userFeedRepository->addOrUpdateUserFeed($feed); - } + // update the last check from time to time to avoid deletion by maintenance tasks + if ($news === [] && (is_null($feed->getLastCheck()) || $now->diff($feed->getLastCheck())->format('s') > 30 * 24 * 3600)) { + $feed->setLastCheck($now->add(new DateInterval('P15D'))); + $userFeedRepository->addOrUpdateUserFeed($feed); } $dates = $notification->get_recent_post_dates_array($conf['recent_post_dates']['RSS']); @@ -137,7 +136,7 @@ public function feed( $item->date = $date->format('c'); $item->author = $conf['rss_feed_author']; - $item->guid = sprintf('%s', 'pics-' . $date->format('c')); + $item->guid = 'pics-' . $date->format('c'); $rss->addItem($item); } diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 0d361b095..1b3e6878f 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -47,7 +47,7 @@ public function mostVisited( $tpl_params['items'][] = $image->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); $tpl_params['thumb_navbar'] = Utils::createNavigationBar( @@ -154,7 +154,7 @@ public function bestRated( $tpl_params['items'][] = $image->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); if (count($tpl_params['items']) > $nb_image_page) { @@ -219,7 +219,7 @@ public function randomList( $tpl_params['items'][] = $image->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); $tpl_params = array_merge( diff --git a/src/Controller/InstallController.php b/src/Controller/InstallController.php index ec51b0f6c..87023f850 100644 --- a/src/Controller/InstallController.php +++ b/src/Controller/InstallController.php @@ -252,7 +252,7 @@ protected function databaseStep(Request $request) $db_params['db_prefix'] = $request->request->get('db_prefix'); } - if (empty($errors)) { + if ($errors === []) { try { $this->phyxoInstaller->installDatabase($db_params); } catch (Exception $e) { @@ -263,10 +263,10 @@ protected function databaseStep(Request $request) $tpl_params = array_merge($tpl_params, $db_params); - if (empty($errors) && $request->isMethod('POST') && $request->request->get('install_database')) { + if ($errors === [] && $request->isMethod('POST') && $request->request->get('install_database')) { $tpl_params['STEP'] = 'user'; } else { - if (!empty($errors)) { + if ($errors !== []) { $tpl_params['errors'] = $errors; } $tpl_params['STEP'] = 'database'; @@ -306,16 +306,14 @@ protected function userStep(Request $request) } if (!$request->request->get('_mail_address')) { $errors[] = $this->translator->trans('mail address must be like xxx@yyy.eee (example : jack@altern.org)', [], 'install'); + } elseif (filter_var($request->request->get('_mail_address'), FILTER_VALIDATE_EMAIL) === false) { + $errors[] = $this->translator->trans('mail address must be like xxx@yyy.eee (example : jack@altern.org)', [], 'install'); } else { - if (filter_var($request->request->get('_mail_address'), FILTER_VALIDATE_EMAIL) === false) { - $errors[] = $this->translator->trans('mail address must be like xxx@yyy.eee (example : jack@altern.org)', [], 'install'); - } else { - $db_params['mail_address'] = $request->request->get('_mail_address'); - $tpl_params['_mail_address'] = $request->request->get('_mail_address'); - } + $db_params['mail_address'] = $request->request->get('_mail_address'); + $tpl_params['_mail_address'] = $request->request->get('_mail_address'); } - if (count($errors) === 0) { + if ($errors === []) { $envParams = (new Dotenv())->parse(file_get_contents($this->localEnvFile . '.tmp')); $_params = parse_url((string) $envParams['DATABASE_URL']); $connectionParams = [ @@ -402,11 +400,11 @@ protected function userStep(Request $request) } } - if (empty($errors) && $request->isMethod('POST') && $request->request->get('install_user')) { + if ($errors === [] && $request->isMethod('POST') && $request->request->get('install_user')) { $tpl_params['STEP'] = 'success'; } else { $tpl_params['STEP'] = 'user'; - if (!empty($errors)) { + if ($errors !== []) { $tpl_params['errors'] = $errors; } } diff --git a/src/Controller/MediaController.php b/src/Controller/MediaController.php index 4d92c20fc..549946986 100644 --- a/src/Controller/MediaController.php +++ b/src/Controller/MediaController.php @@ -223,11 +223,7 @@ protected function needGenerate(string $image_src, string $derivative_src): bool if (is_readable($derivative_src)) { $derivative_mtime = filemtime($derivative_src); - if ($derivative_mtime < $src_mtime) { - $need_generate = true; - } else { - $need_generate = false; - } + $need_generate = $derivative_mtime < $src_mtime; } return $need_generate; diff --git a/src/Controller/PictureController.php b/src/Controller/PictureController.php index 1c619480f..40b8677fa 100644 --- a/src/Controller/PictureController.php +++ b/src/Controller/PictureController.php @@ -112,7 +112,7 @@ public function picture( } } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $tpl_params = array_merge( $tpl_params, $imageMapper->getPicturesFromSelection($element_id, $tpl_params['items'], $type, 0, $extra) @@ -293,7 +293,7 @@ public function picture( $is_favorite = $favoriteRepository->isFavorite($appUserService->getUser()->getId(), $image_id); $tpl_params['favorite'] = [ 'IS_FAVORITE' => $is_favorite, - 'U_FAVORITE' => $this->generateUrl(!$is_favorite ? 'add_to_favorites' : 'remove_from_favorites', ['image_id' => $image_id]) + 'U_FAVORITE' => $this->generateUrl($is_favorite ? 'remove_from_favorites' : 'add_to_favorites', ['image_id' => $image_id]) ]; } @@ -433,11 +433,7 @@ public function picture( if ($comment_form->isSubmitted() && $comment_form->isValid()) { $imageCommentModel = $comment_form->getData(); - if (!$conf['comments_validation'] || $appUserService->isAdmin()) { - $validated = true; - } else { - $validated = false; - } + $validated = !$conf['comments_validation'] || $appUserService->isAdmin(); $comment = new Comment(); $comment->setContent($imageCommentModel->getContent()); @@ -472,13 +468,11 @@ public function picture( 'url' => $this->generateUrl('random_list', ['list' => $element_id]), 'label' => $translator->trans('Random photos'), ]]; - } else { + } elseif ((is_countable($tpl_params['related_categories']) ? count($tpl_params['related_categories']) : 0) > 1) { // @TODO: assign TITLE another way - if ((is_countable($tpl_params['related_categories']) ? count($tpl_params['related_categories']) : 0) > 1) { - $tpl_params['TITLE'] = [$tpl_params['related_categories'][0]]; - } else { - $tpl_params['TITLE'] = $tpl_params['related_categories']; - } + $tpl_params['TITLE'] = [$tpl_params['related_categories'][0]]; + } else { + $tpl_params['TITLE'] = $tpl_params['related_categories']; } $historyEvent = new HistoryEvent($history_section); @@ -487,7 +481,7 @@ public function picture( $historyEvent->setAlbum($album); } - if (count($tags) > 0) { + if ($tags !== []) { $historyEvent->setTagIds( implode( ',', @@ -637,7 +631,7 @@ protected function addMetadataInfos(Metadata $metadata, Conf $conf, string $path $exif = $metadata->getExifData($path, $exif_mapping); - if (count($exif) > 0) { + if ($exif !== []) { $tpl_meta = [ 'TITLE' => $this->translator->trans('EXIF Metadata'), 'lines' => [], @@ -668,7 +662,7 @@ protected function addMetadataInfos(Metadata $metadata, Conf $conf, string $path if ($conf['show_iptc']) { $iptc = $metadata->getIptcData($path, $conf['show_iptc_mapping'], ', '); - if (count($iptc) > 0) { + if ($iptc !== []) { $tpl_meta = [ 'TITLE' => $this->translator->trans('IPTC Metadata'), 'lines' => [], diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index bcdc5bc77..1b3d62bf8 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -70,7 +70,7 @@ public function search( $available_tags = $tagMapper->getAvailableTags($appUserService->getUser()); - if (count($available_tags) > 0) { + if ($available_tags !== []) { usort($available_tags, $tagMapper->alphaCompare(...)); $tpl_params['TAGS'] = $available_tags; } @@ -151,12 +151,7 @@ public function search( /** @phpstan-ignore-next-line */ if ($request->request->has('authors') && is_array($request->request->all('authors')) && (is_countable($request->request->all('authors')) ? count($request->request->all('authors')) : 0) > 0) { - $authors = []; - - foreach ($request->request->all('authors') as $author) { - $authors[] = $author; - } - + $authors = $request->request->all('authors'); $rules['fields']['author'] = [ 'words' => $authors, 'mode' => 'OR', @@ -166,7 +161,7 @@ public function search( if ($request->request->has('cat')) { $rules['fields']['cat'] = [ 'words' => $request->request->all('cat'), - 'sub_inc' => ($request->request->get('subcats-included') == 1) ? true : false, + 'sub_inc' => $request->request->get('subcats-included') == 1, ]; } @@ -197,7 +192,7 @@ public function search( ]; } - if (count($rules) > 0) { + if ($rules !== []) { // default search mode : each clause must be respected $rules['mode'] = 'AND'; @@ -285,7 +280,7 @@ public function searchResults( $cats = array_merge($cats, $search_results['qsearch_details']['matching_cats']); } - if (count($cats) > 0) { + if ($cats !== []) { usort($cats, '\Phyxo\Functions\Utils::name_compare'); $hints = []; foreach ($cats as $cat) { @@ -304,9 +299,8 @@ public function searchResults( } } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); - $tpl_params['thumb_navbar'] = Utils::createNavigationBar( $router, 'search_results', @@ -316,7 +310,6 @@ public function searchResults( $nb_image_page, $conf['paginate_pages_around'] ); - $tpl_params = array_merge( $tpl_params, $imageMapper->getPicturesFromSelection( @@ -326,18 +319,15 @@ public function searchResults( $start ) ); - /** @phpstan-ignore-next-line */ if (!empty($search_results['qsearch_details']) && !empty($search_results['qsearch_details']['unmatched_terms'])) { /** @phpstan-ignore-next-line */ $tpl_params['no_search_results'] = $search_results['qsearch_details']['unmatched_terms']; } - } else { /** @phpstan-ignore-next-line */ - if (!empty($search_results['qsearch_details']) && !empty($search_results['qsearch_details']['q'])) { - /** @phpstan-ignore-next-line */ - $tpl_params['no_search_results'] = $search_results['qsearch_details']['q']; - } + } elseif (!empty($search_results['qsearch_details']) && !empty($search_results['qsearch_details']['q'])) { + /** @phpstan-ignore-next-line */ + $tpl_params['no_search_results'] = $search_results['qsearch_details']['q']; } if ($request->cookies->has('category_view')) { @@ -368,7 +358,7 @@ public function searchRules(AlbumMapper $albumMapper, TagRepository $tagReposito } if (isset($rules['fields']['allwords'])) { - $tpl_params['search_words'] = $translator->trans('searched words : {words}', ['words' => join(', ', $rules['fields']['allwords']['words'])]); + $tpl_params['search_words'] = $translator->trans('searched words : {words}', ['words' => implode(', ', $rules['fields']['allwords']['words'])]); } if (isset($rules['fields']['tags'])) { @@ -381,7 +371,7 @@ public function searchRules(AlbumMapper $albumMapper, TagRepository $tagReposito } if (isset($rules['fields']['author'])) { - $tpl_params['search_words'] = $translator->trans('author(s) : {authors}', ['authors' => join(', ', array_map('strip_tags', $rules['fields']['author']['words']))]); + $tpl_params['search_words'] = $translator->trans('author(s) : {authors}', ['authors' => implode(', ', array_map('strip_tags', $rules['fields']['author']['words']))]); } if (isset($rules['fields']['cat'])) { @@ -397,7 +387,7 @@ public function searchRules(AlbumMapper $albumMapper, TagRepository $tagReposito foreach ($albumMapper->getRepository()->findBy(['id' => $album_ids]) as $album) { $albums[] = $album; } - usort($albums, [AlbumMapper::class, 'globalRankCompare']); + usort($albums, AlbumMapper::globalRankCompare(...)); foreach ($albums as $album) { $tpl_params['search_categories'] = $albumMapper->getAlbumsDisplayName($album->getUppercats(), 'album'); diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 49e4047ec..15ee9ba82 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -11,6 +11,7 @@ namespace App\Controller; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Exception; use DateTime; use DateInterval; @@ -60,7 +61,7 @@ public function login( 'password_route' => $this->generateUrl('forgot_password'), 'last_username' => $last_username, 'csrf_token' => $token, - 'errors' => $error ? $translator->trans('Invalid credentials') : '', + 'errors' => $error instanceof AuthenticationException ? $translator->trans('Invalid credentials') : '', ]); $status_code = 200; diff --git a/src/Controller/TagController.php b/src/Controller/TagController.php index ac2ea0e52..04421b14a 100644 --- a/src/Controller/TagController.php +++ b/src/Controller/TagController.php @@ -93,7 +93,7 @@ public function list(Request $request, AppUserService $appUserService, TagMapper } // flush last letter - if (count($letter['tags']) > 0) { + if ($letter['tags'] !== []) { unset($letter['CHANGE_COLUMN']); $letter['TITLE'] = $current_letter; $tpl_params['letters'][] = $letter; @@ -161,7 +161,7 @@ public function imagesByTags( $tpl_params['items'][] = $image->getId(); } - if (count($tpl_params['items']) > 0) { + if ($tpl_params['items'] !== []) { $nb_image_page = $appUserService->getUser()->getUserInfos()->getNbImagePage(); $tpl_params['thumb_navbar'] = Utils::createNavigationBar( @@ -210,8 +210,9 @@ protected function getTagsContentTitle(TranslatorInterface $translator, array $t $title .= ''; $title .= $translator->trans('number_of_tags', ['count' => count($tags)]); $title .= ' '; + $counter = count($tags); - for ($i = 0; $i < count($tags); $i++) { + for ($i = 0; $i < $counter; $i++) { $title .= $i > 0 ? ' + ' : ''; $title .= 'trans('display photos linked to this tag') . '">'; diff --git a/src/DataMapper/AlbumMapper.php b/src/DataMapper/AlbumMapper.php index cddaf2d72..d6be9930c 100644 --- a/src/DataMapper/AlbumMapper.php +++ b/src/DataMapper/AlbumMapper.php @@ -11,6 +11,7 @@ namespace App\DataMapper; +use App\Entity\Image; use Exception; use DateTime; use App\Entity\Album; @@ -111,8 +112,8 @@ protected function getAlbumsMenu(User $user, array $selected_album = []): array 'TITLE' => $title, 'URL' => $this->router->generate('album', ['album_id' => $album->getId()]), 'LEVEL' => substr_count((string) $album->getGlobalRank(), '.') + 1, - 'SELECTED' => isset($selected_album['id']) && $selected_album['id'] === $album->getId() ? true : false, - 'IS_UPPERCAT' => isset($selected_album['id_uppercat']) && $selected_album['id_uppercat'] === $album->getId() ? true : false, + 'SELECTED' => isset($selected_album['id']) && $selected_album['id'] === $album->getId(), + 'IS_UPPERCAT' => isset($selected_album['id_uppercat']) && $selected_album['id_uppercat'] === $album->getId(), 'count_images' => $userCacheAlbum->getCountImages(), 'icon_ts' => '' ] @@ -204,7 +205,7 @@ public function removeComputedAlbum(array $albums, $album): array /** * Generates breadcrumb from albums list. */ - public function getAlbumDisplayName(array $album_informations, string $url = null): string + public function getAlbumDisplayName(array $album_informations, ?string $url = null): string { $output = ''; $is_first = true; @@ -287,7 +288,7 @@ public function getAlbumsDisplayNameCache(string $uppercats, string $url = '', b if ($single_link) { $single_url = $this->router->generate('album', ['album_id' => $all_albums[count($all_albums) - 1]]); $output .= 'globalRankCompare(...)); + usort($albums, self::globalRankCompare(...)); return $this->displaySelectAlbums($albums, $selecteds, $blockname, $fullname); } @@ -353,9 +354,9 @@ public function displaySelectAlbumsWrapper(array $albums, array $selecteds, stri * Change the parent album of the given albums. * @param int[] $ids */ - public function moveAlbums(array $ids, int $new_parent = null): void + public function moveAlbums(array $ids, ?int $new_parent = null): void { - if (count($ids) === 0) { + if ($ids === []) { return; } @@ -484,7 +485,7 @@ public function setAlbumsStatus(array $album_ids, string $status): void foreach ($this->albumRepository->findBy(['id' => $album_ids]) as $album) { $all_albums[] = $album; } - usort($all_albums, $this->globalRankCompare(...)); + usort($all_albums, self::globalRankCompare(...)); foreach ($all_albums as $album) { $is_top = true; @@ -513,7 +514,7 @@ public function setAlbumsStatus(array $album_ids, string $status): void /** @var Album[] $parent_albums */ $parent_albums = []; - if (count($parent_ids) > 0) { + if ($parent_ids !== []) { foreach ($this->albumRepository->findBy(['id' => $parent_ids]) as $album) { $parent_albums[] = $album->getId(); } @@ -574,7 +575,7 @@ public function getUppercatIds(array $ids): array public function addPermissionOnAlbum(array $album_ids, array $user_ids, bool $apply_on_sub = false): void { // check for emptiness - if (count($album_ids) === 0 || count($user_ids) === 0) { + if ($album_ids === [] || $user_ids === []) { return; } @@ -584,7 +585,7 @@ public function addPermissionOnAlbum(array $album_ids, array $user_ids, bool $ap $cat_ids = array_merge($cat_ids, $this->albumRepository->getSubcatIds($album_ids)); } - if (count($cat_ids) > 0) { + if ($cat_ids !== []) { $users = $this->userRepository->findBy(['id' => $user_ids]); foreach ($this->albumRepository->findByIdsAndStatus($cat_ids, Album::STATUS_PRIVATE) as $album) { @@ -685,7 +686,7 @@ public function createAlbum(string $name, int $user_id, ?Album $parent = null, a /** * Callback used for sorting by global_rank */ - public function globalRankCompare(Album $a, Album $b): int + public static function globalRankCompare(Album $a, Album $b): int { return strnatcasecmp((string) $a->getGlobalRank(), (string) $b->getGlobalRank()); } @@ -737,6 +738,7 @@ public function updateGlobalRank(): void $current_parent = null; foreach ($this->getCacheAlbums() as $id => $album) { + /** @phpstan-ignore-next-line */ if (!is_null($current_parent) && $album->getParent()->getId() !== $current_parent->getId()) { $current_rank = 0; $current_parent = $album->getParent(); @@ -804,8 +806,8 @@ public function getAlbumsRefDate(array $ids, string $field = 'date_available', s } } - if (count($to_compare) > 0) { - $ref_dates[$album_id] = 'max' == $minmax ? max($to_compare) : min($to_compare); + if ($to_compare !== []) { + $ref_dates[$album_id] = 'max' === $minmax ? max($to_compare) : min($to_compare); } else { $ref_dates[$album_id] = null; } @@ -911,7 +913,7 @@ public function updateAlbums(array $ids = []): void */ public function deleteAlbums(array $ids = []): void { - if (count($ids) === 0) { + if ($ids === []) { return; } @@ -971,7 +973,7 @@ public function associateImagesToAlbums(array $image_ids, array $album_ids): voi */ public function moveImagesToAlbums(array $image_ids = [], array $album_ids = []): void { - if (count($image_ids) === 0) { + if ($image_ids === []) { return; } @@ -983,7 +985,7 @@ public function moveImagesToAlbums(array $image_ids = [], array $album_ids = []) // let's first break links with all old albums but their "storage album" $this->imageAlbumRepository->deleteByAlbum($album_ids, $image_ids); - if (count($new_album_ids) > 0) { + if ($new_album_ids !== []) { $this->associateImagesToAlbums($image_ids, $new_album_ids); } } @@ -1039,11 +1041,11 @@ public function getAlbumThumbnails(User $user, array $albums): array } elseif ($album->getRepresentativePictureId()) { // if a representative picture is set, it has priority $image_id = $album->getRepresentativePictureId(); } elseif ($this->conf['allow_random_representative']) { // searching a random representant among elements in sub-categories - if ($random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums())) { + if (($random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums())) instanceof Image) { $image_id = $random_image->getId(); } } elseif ($userCacheAlbum->getCountAlbums() > 0 && $userCacheAlbum->getCountImages() > 0) { // searching a random representant among representant of sub-categories - if ($random_image = $this->getRepository()->findRandomRepresentantAmongSubAlbums($album->getUppercats())) { + if (($random_image = $this->getRepository()->findRandomRepresentantAmongSubAlbums($album->getUppercats())) instanceof Album) { $image_id = $random_image->getId(); } } @@ -1060,7 +1062,7 @@ public function getAlbumThumbnails(User $user, array $albums): array unset($image_id); } - usort($album_thumbnails, $this->globalRankCompare(...)); + usort($album_thumbnails, self::globalRankCompare(...)); return [$album_thumbnails, $image_ids, $user_representative_updates_for]; } @@ -1082,31 +1084,29 @@ public function getInfosOfImages(User $user, array $albums, array $image_ids, Im } $missing_image_ids = array_values(array_diff($image_ids, $bad_level_ids, array_keys($infos_of_images))); - if (count($missing_image_ids)) { - // problem: we must not display the thumbnail of a photo which has a higher privacy level than user privacy level - foreach ($missing_image_ids as $id) { - // * what is the represented album? - // * find a random photo matching user permissions - // * register it at user_representative_picture_id - // * set it as the representative_picture_id for the album - - foreach ($albums as $album) { - if ($album->getRepresentativePictureId() === $id) { - // searching a random representant among elements in sub-categories - $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums()); - - if (!is_null($random_image) && !in_array($random_image->getId(), $image_ids)) { - $infos_of_images[$random_image->getId()] = [$random_image->toArray(), 'image' => $random_image]; - - if ($this->conf['representative_cache_on_level']) { - // @TODO save representative picture in cache - } - - $album->setRepresentativePictureId($random_image->getId()); + // problem: we must not display the thumbnail of a photo which has a higher privacy level than user privacy level + foreach ($missing_image_ids as $id) { + // * what is the represented album? + // * find a random photo matching user permissions + // * register it at user_representative_picture_id + // * set it as the representative_picture_id for the album + + foreach ($albums as $album) { + if ($album->getRepresentativePictureId() === $id) { + // searching a random representant among elements in sub-categories + $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums()); + + if (!is_null($random_image) && !in_array($random_image->getId(), $image_ids)) { + $infos_of_images[$random_image->getId()] = [$random_image->toArray(), 'image' => $random_image]; + + if ($this->conf['representative_cache_on_level']) { + // @TODO save representative picture in cache } - $this->getRepository()->addOrUpdateAlbum($album); + $album->setRepresentativePictureId($random_image->getId()); } + + $this->getRepository()->addOrUpdateAlbum($album); } } } diff --git a/src/DataMapper/CommentMapper.php b/src/DataMapper/CommentMapper.php index 97da6c72a..272284ff4 100644 --- a/src/DataMapper/CommentMapper.php +++ b/src/DataMapper/CommentMapper.php @@ -98,11 +98,9 @@ public function insertUserComment(array &$comm, array &$infos): string $comm['author_id'] = $this->userMapper->getDefaultUser()->getId(); // if a guest try to use the name of an already existing user, he must be rejected - if ($comm['author'] !== 'guest') { - if ($this->userRepository->isUserExists($comm['author'])) { - $infos[] = $this->translator->trans('This login is already used by another user'); - $comment_action = 'reject'; - } + if ($comm['author'] !== 'guest' && $this->userRepository->isUserExists($comm['author'])) { + $infos[] = $this->translator->trans('This login is already used by another user'); + $comment_action = 'reject'; } } else { $comm['author'] = $this->getUser()->getUserIdentifier(); @@ -131,7 +129,7 @@ public function insertUserComment(array &$comm, array &$infos): string // email if (empty($comm['email'])) { - if (!empty($this->getUser()->getMailAddress())) { + if (!in_array($this->getUser()->getMailAddress(), [null, '', '0'], true)) { $comm['email'] = $this->getUser()->getMailAddress(); } elseif ($this->conf['comments_email_mandatory']) { $infos[] = $this->translator->trans('Email address is missing. Please specify an email address.'); @@ -147,7 +145,7 @@ public function insertUserComment(array &$comm, array &$infos): string $anti_flood_date = new DateTime(); $anti_flood_date->sub(new DateInterval(sprintf('PT%dS', $this->conf['anti-flood-time']))); - if ($this->getRepository()->doestAuthorPostMessageAfterThan($comm['author_id'], $anti_flood_date, !$this->appUserService->isGuest() ? $anonymous_id : md5('::1'))) { + if ($this->getRepository()->doestAuthorPostMessageAfterThan($comm['author_id'], $anti_flood_date, $this->appUserService->isGuest() ? md5('::1') : $anonymous_id)) { $infos[] = $this->translator->trans('Anti-flood system : please wait for a moment before trying to post another comment'); $comment_action = 'reject'; } @@ -161,8 +159,8 @@ public function insertUserComment(array &$comm, array &$infos): string ])); $this->userCacheRepository->invalidateNumberAvailableComments(); - if (($this->conf['email_admin_on_comment'] && 'validate' == $comment_action) - || ($this->conf['email_admin_on_comment_validation'] && 'moderate' == $comment_action)) { + if (($this->conf['email_admin_on_comment'] && 'validate' === $comment_action) + || ($this->conf['email_admin_on_comment_validation'] && 'moderate' === $comment_action)) { $this->eventDispatcher->dispatch(new CommentEvent($comm, $comment_action)); } } diff --git a/src/DataMapper/ImageMapper.php b/src/DataMapper/ImageMapper.php index a97f3f94a..1262831a5 100644 --- a/src/DataMapper/ImageMapper.php +++ b/src/DataMapper/ImageMapper.php @@ -64,7 +64,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str { $tpl_params = []; - if (count($selection) === 0) { + if ($selection === []) { return []; } @@ -86,12 +86,10 @@ public function getPicturesFromSelection($element_id, array $selection = [], str $section = 'album'; } - if (count($pictures) > 0) { - if ($this->conf['activate_comments'] && $this->userMapper->getUser()->getUserInfos()->getShowNbComments()) { - $nb_comments_of = []; - foreach ($this->commentRepository->countGroupByImage($selection) as $comment) { - $nb_comments_of[$comment['image_id']] = $comment['nb_comments']; - } + if ($pictures !== [] && ($this->conf['activate_comments'] && $this->userMapper->getUser()->getUserInfos()->getShowNbComments())) { + $nb_comments_of = []; + foreach ($this->commentRepository->countGroupByImage($selection) as $comment) { + $nb_comments_of[$comment['image_id']] = $comment['nb_comments']; } } @@ -105,7 +103,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str 'element_id' => $element_id, ] ); - } elseif (in_array($section, ['calendar_categories'])) { + } elseif ($section === 'calendar_categories') { $url = $this->router->generate( 'picture_categories_from_calendar', [ @@ -114,7 +112,7 @@ public function getPicturesFromSelection($element_id, array $selection = [], str 'extra' => 'extr', ] ); - } elseif (in_array($section, ['from_calendar'])) { + } elseif ($section === 'from_calendar') { $url = $this->router->generate( 'picture_from_calendar', [ @@ -229,7 +227,7 @@ public function deleteElements(array $ids, bool $physical_deletion = false): int foreach ($this->albumMapper->getRepository()->findRepresentants($ids) as $album) { $album_ids[] = $album->getId(); } - if (count($album_ids) > 0) { + if ($album_ids !== []) { $this->albumMapper->updateAlbums($album_ids); } @@ -302,11 +300,11 @@ public function getThumbnailTitle(array $info, string $title, ?string $comment = $details[] = $this->translator->trans('number_of_comments', ['count' => $info['nb_comments']]); } - if (count($details) > 0) { + if ($details !== []) { $title .= ' (' . implode(', ', $details) . ')'; } - if (!empty($comment)) { + if ($comment !== null && $comment !== '' && $comment !== '0') { $comment = strip_tags($comment); $title .= ' ' . substr($comment, 0, 100) . (strlen($comment) > 100 ? '...' : ''); } diff --git a/src/DataMapper/RateMapper.php b/src/DataMapper/RateMapper.php index 5c490903d..47d931f67 100644 --- a/src/DataMapper/RateMapper.php +++ b/src/DataMapper/RateMapper.php @@ -44,19 +44,17 @@ public function ratePicture(int $image_id, int $note, string $anonymous_id, stri $user_anonymous = $this->appUserService->isGuest(); - if ($user_anonymous) { - if ($anonymous_id !== $save_anonymous_id) { // client has changed his IP address or he's trying to fool us - $rate = $this->getRepository()->findOneBy([ - 'user' => $this->userMapper->getUser()->getId(), - 'image' => $image_id, - 'anonymous_id' => $anonymous_id - ]); - if (!is_null($rate)) { - $this->getRepository()->delete($rate); - } - - $this->getRepository()->updateAnonymousIdField($anonymous_id, $this->userMapper->getUser()->getId(), $save_anonymous_id); + if ($user_anonymous && $anonymous_id !== $save_anonymous_id) { + // client has changed his IP address or he's trying to fool us + $rate = $this->getRepository()->findOneBy([ + 'user' => $this->userMapper->getUser()->getId(), + 'image' => $image_id, + 'anonymous_id' => $anonymous_id + ]); + if (!is_null($rate)) { + $this->getRepository()->delete($rate); } + $this->getRepository()->updateAnonymousIdField($anonymous_id, $this->userMapper->getUser()->getId(), $save_anonymous_id); } $this->getRepository()->deleteImageRateForUser($this->userMapper->getUser()->getId(), $image_id, $user_anonymous ? $anonymous_id : null); diff --git a/src/DataMapper/SearchMapper.php b/src/DataMapper/SearchMapper.php index 9d4d57c35..109058fea 100644 --- a/src/DataMapper/SearchMapper.php +++ b/src/DataMapper/SearchMapper.php @@ -67,14 +67,10 @@ public function getRegularSearchResults(array $rules, User $user): array $items[] = $image->getId(); } - if (count($tag_items) > 0) { + if ($tag_items !== []) { switch ($rules['mode']) { case 'AND': - if (count($items) === 0) { - $items = $tag_items; - } else { - $items = array_values(array_intersect($items, $tag_items)); - } + $items = $items === [] ? $tag_items : array_values(array_intersect($items, $tag_items)); break; case 'OR': $items = array_unique([...$items, ...$tag_items]); diff --git a/src/DataMapper/TagMapper.php b/src/DataMapper/TagMapper.php index fb727ca44..c751d18f6 100644 --- a/src/DataMapper/TagMapper.php +++ b/src/DataMapper/TagMapper.php @@ -163,7 +163,7 @@ public function getRelatedTags(User $user, int $image_id, int $max_tags, array $ */ public function getCommonTags(User $user, array $items, int $max_tags, array $excluded_tag_ids = []) { - if (count($items) === 0) { + if ($items === []) { return []; } @@ -213,7 +213,7 @@ public function prepareTagsListForUI(array $tags, $only_user_language = true) : } } usort($taglist, '\Phyxo\Functions\Utils::tag_alpha_compare'); - if (count($altlist)) { + if ($altlist !== []) { usort($altlist, '\Phyxo\Functions\Utils::tag_alpha_compare'); $taglist = [...$taglist, ...$altlist]; } @@ -285,7 +285,7 @@ public function tagIdFromTagName(string $tag_name) : int */ public function addTags(array $tag_ids, array $image_ids, User $user): void { - if (count($tag_ids) === 0 or count($image_ids) === 0) { + if ($tag_ids === [] || $image_ids === []) { return; } @@ -339,7 +339,7 @@ public function deleteTags(array $tag_ids): void */ public function setTagsOf(array $tags_of, User $user): void { - if (count($tags_of) > 0) { + if ($tags_of !== []) { $tag_ids = []; foreach ($tags_of as $ids) { $tag_ids = array_merge($tag_ids, $ids); @@ -378,7 +378,7 @@ public function deleteOrphanTags(): void $orphan_tags[] = $tag->getId(); } - if (count($orphan_tags) > 0) { + if ($orphan_tags !== []) { $this->deleteTags($orphan_tags); } } @@ -388,7 +388,7 @@ public function deleteOrphanTags(): void */ public function associateTags(array $tag_ids, int $image_id, User $user): void { - if (count($tag_ids) === 0) { + if ($tag_ids === []) { return; } @@ -409,7 +409,7 @@ public function associateTags(array $tag_ids, int $image_id, User $user): void */ public function rejectTags(array $elements): void { - if (empty($elements)) { + if ($elements === []) { return; } $this->imageTagRepository->deleteImageTags($elements); @@ -420,7 +420,7 @@ public function rejectTags(array $elements): void */ public function validateTags(array $elements): void { - if (count($elements) === 0) { + if ($elements === []) { return; } @@ -437,7 +437,7 @@ public function validateTags(array $elements): void */ public function dissociateTags(array $tag_ids, int $image_id): void { - if (count($tag_ids) === 0) { + if ($tag_ids === []) { return; } @@ -493,7 +493,7 @@ public function sync_metadata(array $ids, User $user): void foreach ($this->imageRepository->findBy(['id' => $ids]) as $image) { $metadata = $this->metadata->getSyncMetadata($image->toArray()); - if (count($metadata) === 0) { + if ($metadata === []) { continue; } @@ -547,7 +547,7 @@ public function invalidateUserCacheNbTags(): void */ public function addLevelToTags(array $tags = [], int $tags_levels = 5) : array { - if (count($tags) === 0) { + if ($tags === []) { return $tags; } diff --git a/src/Entity/Album.php b/src/Entity/Album.php index a5949a163..45f3c75b7 100644 --- a/src/Entity/Album.php +++ b/src/Entity/Album.php @@ -440,7 +440,7 @@ public function toArray(): array return [ 'id' => $this->getId(), 'name' => $this->getName(), - 'id_uppercat' => $this->getParent() ? $this->getParent()->getId() : null, + 'id_uppercat' => $this->getParent() instanceof \App\Entity\Album ? $this->getParent()->getId() : null, 'comment' => $this->getComment(), 'dir' => $this->getDir(), 'rank' => $this->getRank(), diff --git a/src/Entity/User.php b/src/Entity/User.php index 2ec445441..0ba58ff33 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -230,12 +230,7 @@ public function isEqualTo(UserInterface $user): bool if ($this->username !== $user->getUsername()) { return false; } - - if ($this->getRoles() !== $user->getRoles()) { - return false; - } - - return true; + return $this->getRoles() === $user->getRoles(); } public static function getRoleFromStatus(string $status): string diff --git a/src/EventListener/UserStatusListener.php b/src/EventListener/UserStatusListener.php index 1c3ee97b8..564eca070 100644 --- a/src/EventListener/UserStatusListener.php +++ b/src/EventListener/UserStatusListener.php @@ -25,7 +25,7 @@ public function postLoad(PostLoadEventArgs $args) $entity = $args->getObject(); if ($entity instanceof UserInfos) { - if ($entity->getUser() !== null) { + if ($entity->getUser() instanceof User) { $entity->getUser()->addRole(User::getRoleFromStatus($entity->getStatus())); } } elseif ($entity instanceof User) { diff --git a/src/EventSubscriber/CheckInstallSubscriber.php b/src/EventSubscriber/CheckInstallSubscriber.php index 210b50ef3..8f6310a14 100644 --- a/src/EventSubscriber/CheckInstallSubscriber.php +++ b/src/EventSubscriber/CheckInstallSubscriber.php @@ -41,6 +41,7 @@ public function onKernelException(ExceptionEvent $event) $response = new RedirectResponse($install_url); $event->setResponse($response); } + return null; } public static function getSubscribedEvents(): array diff --git a/src/EventSubscriber/ExtensionManagerSubscriber.php b/src/EventSubscriber/ExtensionManagerSubscriber.php index b2dd48329..a2dcd0fc5 100644 --- a/src/EventSubscriber/ExtensionManagerSubscriber.php +++ b/src/EventSubscriber/ExtensionManagerSubscriber.php @@ -90,14 +90,11 @@ public function checkAvailability(ConsoleCommandEvent $event): void } } } - } else { - if (isset($this->extensionCollection->getExtensionsByName()[$command->getName()])) { - $command_name = $this->extensionCollection->getExtensionsByName()[$command->getName()]; - $pluginsForCommand = array_filter($this->plugins->getDbPlugins(Plugin::INACTIVE), fn ($p) => $p->getId() === $command_name); - - if (count($pluginsForCommand) > 0) { - $event->disableCommand(); - } + } elseif (isset($this->extensionCollection->getExtensionsByName()[$command->getName()])) { + $command_name = $this->extensionCollection->getExtensionsByName()[$command->getName()]; + $pluginsForCommand = array_filter($this->plugins->getDbPlugins(Plugin::INACTIVE), fn ($p) => $p->getId() === $command_name); + if ($pluginsForCommand !== []) { + $event->disableCommand(); } } } diff --git a/src/EventSubscriber/HistorySubscriber.php b/src/EventSubscriber/HistorySubscriber.php index 72d0c901e..50def7977 100644 --- a/src/EventSubscriber/HistorySubscriber.php +++ b/src/EventSubscriber/HistorySubscriber.php @@ -11,6 +11,8 @@ namespace App\EventSubscriber; +use App\Entity\Album; +use App\Entity\Image; use DateTime; use App\DataMapper\UserMapper; use App\Entity\History; @@ -53,10 +55,10 @@ public function onVisit(HistoryEvent $event) $history->setTime($now); $history->setSection($event->getSection()); $history->setUser($this->appUserService->getUser()); - if ($event->getAlbum()) { + if ($event->getAlbum() instanceof Album) { $history->setAlbum($event->getAlbum()); } - if ($event->getImage()) { + if ($event->getImage() instanceof Image) { $history->setImage($event->getImage()); } $history->setIp(md5($event->getIp())); diff --git a/src/EventSubscriber/TablePrefixSubscriber.php b/src/EventSubscriber/TablePrefixSubscriber.php index de03c8192..93eb3c3b2 100644 --- a/src/EventSubscriber/TablePrefixSubscriber.php +++ b/src/EventSubscriber/TablePrefixSubscriber.php @@ -43,7 +43,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event) $classMetadata->setSequenceGeneratorDefinition($newDefinition); $em = $event->getEntityManager(); - if (isset($classMetadata->idGenerator)) { + if ($classMetadata->idGenerator !== null) { $sequenceGenerator = new SequenceGenerator( $em->getConfiguration()->getQuoteStrategy()->getSequenceName( $newDefinition, diff --git a/src/Form/ImageCommentType.php b/src/Form/ImageCommentType.php index a6c97ddcb..4e0a742c0 100644 --- a/src/Form/ImageCommentType.php +++ b/src/Form/ImageCommentType.php @@ -54,7 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ); } - if (!$this->userMapper->isClassicUser() || empty($this->appUserService->getUser()->getMailAddress())) { + if (!$this->userMapper->isClassicUser() || in_array($this->appUserService->getUser()->getMailAddress(), [null, '', '0'], true)) { $builder->add( 'mail_address', EmailType::class, diff --git a/src/Form/Model/CommentFilterModel.php b/src/Form/Model/CommentFilterModel.php index 6ae640055..06178d6e8 100644 --- a/src/Form/Model/CommentFilterModel.php +++ b/src/Form/Model/CommentFilterModel.php @@ -86,7 +86,7 @@ public function toArray(): array $params['keyword'] = $this->keyword; } - if (count($this->albums) > 0) { + if ($this->albums !== []) { $params['album_ids'] = $this->albums; } diff --git a/src/Form/Transformer/ConfToDisplayConfigurationTransformer.php b/src/Form/Transformer/ConfToDisplayConfigurationTransformer.php index 3e112b4d7..71b9afdac 100644 --- a/src/Form/Transformer/ConfToDisplayConfigurationTransformer.php +++ b/src/Form/Transformer/ConfToDisplayConfigurationTransformer.php @@ -48,24 +48,6 @@ public function transform($conf): DisplayConfigurationModel */ public function reverseTransform($displayConfigurationModel): array { - $partial_conf = []; - $partial_conf['menubar_filter_icon'] = ['value' => $displayConfigurationModel->getMenubarFilterIcon(), 'type' => 'boolean']; - $partial_conf['index_new_icon'] = ['value' => $displayConfigurationModel->getIndexNewIcon(), 'type' => 'boolean']; - $partial_conf['index_flat_icon'] = ['value' => $displayConfigurationModel->getIndexFlatIcon(), 'type' => 'boolean']; - $partial_conf['index_sort_order_input'] = ['value' => $displayConfigurationModel->getIndexSortOrderInput(), 'type' => 'boolean']; - $partial_conf['index_posted_date_icon'] = ['value' => $displayConfigurationModel->getIndexPostedDateIcon(), 'type' => 'boolean']; - $partial_conf['index_created_date_icon'] = ['value' => $displayConfigurationModel->getIndexCreatedDateIcon(), 'type' => 'boolean']; - $partial_conf['nb_categories_page'] = ['value' => $displayConfigurationModel->getNbCategoriesPage(), 'type' => 'integer']; - - $partial_conf['picture_metadata_icon'] = ['value' => $displayConfigurationModel->getPictureMetadataIcon(), 'type' => 'boolean']; - $partial_conf['picture_download_icon'] = ['value' => $displayConfigurationModel->getPictureDownloadIcon(), 'type' => 'boolean']; - $partial_conf['picture_favorite_icon'] = ['value' => $displayConfigurationModel->getPictureFavoriteIcon(), 'type' => 'boolean']; - $partial_conf['picture_navigation_icons'] = ['value' => $displayConfigurationModel->getPictureNavigationIcons(), 'type' => 'boolean']; - $partial_conf['picture_navigation_thumb'] = ['value' => $displayConfigurationModel->getPictureNavigationThumb(), 'type' => 'boolean']; - $partial_conf['picture_menu'] = ['value' => $displayConfigurationModel->getPictureMenu(), 'type' => 'boolean']; - - $partial_conf['picture_informations'] = ['value' => $displayConfigurationModel->getPictureInformations(), 'type' => 'json']; - - return $partial_conf; + return ['menubar_filter_icon' => ['value' => $displayConfigurationModel->getMenubarFilterIcon(), 'type' => 'boolean'], 'index_new_icon' => ['value' => $displayConfigurationModel->getIndexNewIcon(), 'type' => 'boolean'], 'index_flat_icon' => ['value' => $displayConfigurationModel->getIndexFlatIcon(), 'type' => 'boolean'], 'index_sort_order_input' => ['value' => $displayConfigurationModel->getIndexSortOrderInput(), 'type' => 'boolean'], 'index_posted_date_icon' => ['value' => $displayConfigurationModel->getIndexPostedDateIcon(), 'type' => 'boolean'], 'index_created_date_icon' => ['value' => $displayConfigurationModel->getIndexCreatedDateIcon(), 'type' => 'boolean'], 'nb_categories_page' => ['value' => $displayConfigurationModel->getNbCategoriesPage(), 'type' => 'integer'], 'picture_metadata_icon' => ['value' => $displayConfigurationModel->getPictureMetadataIcon(), 'type' => 'boolean'], 'picture_download_icon' => ['value' => $displayConfigurationModel->getPictureDownloadIcon(), 'type' => 'boolean'], 'picture_favorite_icon' => ['value' => $displayConfigurationModel->getPictureFavoriteIcon(), 'type' => 'boolean'], 'picture_navigation_icons' => ['value' => $displayConfigurationModel->getPictureNavigationIcons(), 'type' => 'boolean'], 'picture_navigation_thumb' => ['value' => $displayConfigurationModel->getPictureNavigationThumb(), 'type' => 'boolean'], 'picture_menu' => ['value' => $displayConfigurationModel->getPictureMenu(), 'type' => 'boolean'], 'picture_informations' => ['value' => $displayConfigurationModel->getPictureInformations(), 'type' => 'json']]; } } diff --git a/src/Form/Transformer/UserToUserInfosTransformer.php b/src/Form/Transformer/UserToUserInfosTransformer.php index 3c38e224d..f62100949 100644 --- a/src/Form/Transformer/UserToUserInfosTransformer.php +++ b/src/Form/Transformer/UserToUserInfosTransformer.php @@ -25,10 +25,7 @@ public function __construct(private readonly LanguageRepository $languageReposit { } - /** - * @param UserInfos $userInfos - */ - public function transform($userInfos): UserInfosModel + public function transform(mixed $userInfos): UserInfosModel { if (!$userInfos instanceof UserInfos) { throw new LogicException('The UserInfosType can only be used with UserInfos objects'); diff --git a/src/Form/Transformer/UserToUserProfileTransformer.php b/src/Form/Transformer/UserToUserProfileTransformer.php index 1a35788bf..20049cddf 100644 --- a/src/Form/Transformer/UserToUserProfileTransformer.php +++ b/src/Form/Transformer/UserToUserProfileTransformer.php @@ -24,9 +24,6 @@ public function __construct(private readonly UserRepository $userRepository) { } - /** - * @param User $user - */ public function transform(mixed $user = null): UserProfileModel { if (is_null($user)) { diff --git a/src/Install/PhyxoInstaller.php b/src/Install/PhyxoInstaller.php index 4468e7340..aa2f4b721 100644 --- a/src/Install/PhyxoInstaller.php +++ b/src/Install/PhyxoInstaller.php @@ -228,10 +228,8 @@ protected function getQueriesFromFile(string $dblayer, string $filepath, string $query = str_replace($replaced, $replacing, $query); // we don't execute "DROP TABLE" queries if (!preg_match('/^DROP TABLE/i', $query)) { - if ($dblayer === 'mysql') { - if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches)) { - $query = $matches[1] . ' DEFAULT CHARACTER SET utf8' . ';'; - } + if ($dblayer === 'mysql' && preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches)) { + $query = $matches[1] . ' DEFAULT CHARACTER SET utf8' . ';'; } $queries[] = $query; } diff --git a/src/Metadata.php b/src/Metadata.php index 7b772855c..e5ff61b0c 100644 --- a/src/Metadata.php +++ b/src/Metadata.php @@ -76,20 +76,16 @@ public function getSyncIptcData(string $file): array $iptc = $this->getIptcData($file, $map); foreach ($iptc as $iptc_key => $value) { - if (in_array($iptc_key, ['date_creation', 'date_available'])) { - if (preg_match('/(\d{4})(\d{2})(\d{2})/', (string) $value, $matches)) { - $year = (int) $matches[1]; - $month = (int) $matches[2]; - $day = (int) $matches[3]; - - if (!checkdate($month, $day, $year)) { - // we suppose the year is correct - $month = 1; - $day = 1; - } - - $iptc[$iptc_key] = DateTime::createFromFormat('Y-m-d', "{$year}-{$month}-{$day}"); + if (in_array($iptc_key, ['date_creation', 'date_available']) && preg_match('/(\d{4})(\d{2})(\d{2})/', (string) $value, $matches)) { + $year = (int) $matches[1]; + $month = (int) $matches[2]; + $day = (int) $matches[3]; + if (!checkdate($month, $day, $year)) { + // we suppose the year is correct + $month = 1; + $day = 1; } + $iptc[$iptc_key] = DateTime::createFromFormat('Y-m-d', "{$year}-{$month}-{$day}"); } } @@ -134,12 +130,9 @@ public function getExifData(string $filename, array $map): array // GPS data $gps_exif = array_intersect_key($exif, array_flip(['GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude'])); - if (count($gps_exif) === 4) { - if (is_array($gps_exif['GPSLatitude']) && in_array($gps_exif['GPSLatitudeRef'], ['S', 'N']) - && is_array($gps_exif['GPSLongitude']) && in_array($gps_exif['GPSLongitudeRef'], ['W', 'E'])) { - $result['latitude'] = $this->parseExifGpsData($gps_exif['GPSLatitude'], $gps_exif['GPSLatitudeRef']); - $result['longitude'] = $this->parseExifGpsData($gps_exif['GPSLongitude'], $gps_exif['GPSLongitudeRef']); - } + if (count($gps_exif) === 4 && (is_array($gps_exif['GPSLatitude']) && in_array($gps_exif['GPSLatitudeRef'], ['S', 'N']) && is_array($gps_exif['GPSLongitude']) && in_array($gps_exif['GPSLongitudeRef'], ['W', 'E']))) { + $result['latitude'] = $this->parseExifGpsData($gps_exif['GPSLatitude'], $gps_exif['GPSLatitudeRef']); + $result['longitude'] = $this->parseExifGpsData($gps_exif['GPSLongitude'], $gps_exif['GPSLongitudeRef']); } } @@ -164,8 +157,8 @@ public function getSyncExifData(string $file): array foreach ($exif as $exif_key => $value) { if (in_array($exif_key, ['date_creation', 'date_available'])) { if (preg_match('/^(\d{4}).(\d{2}).(\d{2}) (\d{2}).(\d{2}).(\d{2})/', (string) $value, $matches)) { - if ($matches[1] != '0000' && $matches[2] != '00' && $matches[3] != '00' - && $matches[4] != '00' && $matches[5] != '00' && $matches[6] != '00') { + if ($matches[1] !== '0000' && $matches[2] !== '00' && $matches[3] !== '00' + && $matches[4] !== '00' && $matches[5] !== '00' && $matches[6] !== '00') { $exif[$exif_key] = DateTime::createFromFormat( 'Y-m-d H:i:s', $matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6] @@ -206,7 +199,7 @@ public function parseExifGpsData(array $raw, string $ref): float $v = (int) $raw[0] + (int) $raw[1] / 60 + (int) $raw[2] / 3600; $ref = strtoupper($ref); - if ($ref == 'S' or $ref == 'W') { + if ($ref === 'S' || $ref === 'W') { $v = -$v; } @@ -219,32 +212,30 @@ public function parseExifGpsData(array $raw, string $ref): float public function cleanIptcValue(string $value): string { // strip leading zeros (weird Kodak Scanner software) - while (isset($value[0]) && $value[0] == chr(0)) { + while (isset($value[0]) && $value[0] === chr(0)) { $value = substr($value, 1); } // remove binary nulls $value = str_replace(chr(0x00), ' ', $value); - if (preg_match('/[\x80-\xff]/', $value)) { - // apparently mac uses some MacRoman crap encoding. I don't know - // how to detect it so a plugin should do the trick. - if (($qual = Language::qualify_utf8($value)) != 0) { // has non ascii chars - if ($qual > 0) { - $input_encoding = 'utf-8'; - } else { - $input_encoding = 'iso-8859-1'; - if (function_exists('iconv') || function_exists('mb_convert_encoding')) { - // using windows-1252 because it supports additional characters - // such as "oe" in a single character (ligature). About the - // difference between Windows-1252 and ISO-8859-1: the characters - // 0x80-0x9F will not convert correctly. But these are control - // characters which are almost never used. - $input_encoding = 'windows-1252'; - } + // apparently mac uses some MacRoman crap encoding. I don't know + // how to detect it so a plugin should do the trick. + if (preg_match('/[\x80-\xff]/', $value) && ($qual = Language::qualify_utf8($value)) != 0) { + // has non ascii chars + if ($qual > 0) { + $input_encoding = 'utf-8'; + } else { + $input_encoding = 'iso-8859-1'; + if (function_exists('iconv') || function_exists('mb_convert_encoding')) { + // using windows-1252 because it supports additional characters + // such as "oe" in a single character (ligature). About the + // difference between Windows-1252 and ISO-8859-1: the characters + // 0x80-0x9F will not convert correctly. But these are control + // characters which are almost never used. + $input_encoding = 'windows-1252'; } - - $value = Utils::convert_charset($value, $input_encoding, 'utf-8'); } + $value = Utils::convert_charset($value, $input_encoding, 'utf-8'); } return $value; diff --git a/src/Notification.php b/src/Notification.php index 4ed0aa3d0..3d01db454 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -39,7 +39,7 @@ class Notification { - /** @var array $env */ + /** @var array $env */ private array $env; /** @var string[] $infos */ @@ -75,7 +75,7 @@ public function __construct( /** * Returns number of new comments between two dates. */ - public function nb_new_comments(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function nb_new_comments(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } @@ -85,7 +85,7 @@ public function nb_new_comments(DateTimeInterface $start = null, DateTimeInterfa * * @return Comment[] */ - public function new_comments(DateTimeInterface $start = null, DateTimeInterface $end = null): array + public function new_comments(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): array { return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } @@ -93,7 +93,7 @@ public function new_comments(DateTimeInterface $start = null, DateTimeInterface /** * Returns number of unvalidated comments between two dates. */ - public function nb_unvalidated_comments(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function nb_unvalidated_comments(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { return $this->commentRepository->getUnvalidatedComments($count_only = true, $start, $end); } @@ -101,7 +101,7 @@ public function nb_unvalidated_comments(DateTimeInterface $start = null, DateTim /** * Returns number of new photos between two dates. */ - public function nb_new_elements(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function nb_new_elements(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } @@ -111,7 +111,7 @@ public function nb_new_elements(DateTimeInterface $start = null, DateTimeInterfa * * @return Image[] */ - public function new_elements(DateTimeInterface $start = null, DateTimeInterface $end = null): array + public function new_elements(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): array { return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } @@ -119,7 +119,7 @@ public function new_elements(DateTimeInterface $start = null, DateTimeInterface /** * Returns number of updated albums between two dates. */ - public function nb_updated_albums(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function nb_updated_albums(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } @@ -129,7 +129,7 @@ public function nb_updated_albums(DateTimeInterface $start = null, DateTimeInter * * @return Album[]|int */ - public function updated_albums(DateTimeInterface $start = null, DateTimeInterface $end = null): array|int + public function updated_albums(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): array|int { return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } @@ -137,7 +137,7 @@ public function updated_albums(DateTimeInterface $start = null, DateTimeInterfac /** * Returns number of new users between two dates. */ - public function nb_new_users(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function nb_new_users(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { return $this->userInfosRepository->countNewUsers($start, $end); } @@ -147,7 +147,7 @@ public function nb_new_users(DateTimeInterface $start = null, DateTimeInterface * * @return UserInfos[] */ - public function new_users(DateTimeInterface $start = null, DateTimeInterface $end = null) + public function new_users(?DateTimeInterface $start = null, ?DateTimeInterface $end = null) { return $this->userInfosRepository->getNewUsers($start, $end); } @@ -160,7 +160,7 @@ public function new_users(DateTimeInterface $start = null, DateTimeInterface $en * unvalidated comments, number of new users. * @todo number of unvalidated elements */ - public function news_exists(DateTimeInterface $start = null, DateTimeInterface $end = null): bool + public function news_exists(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): bool { return (($this->nb_new_comments($start, $end) > 0) || ($this->nb_new_elements($start, $end) > 0) || ($this->nb_updated_albums($start, $end) > 0) || (($this->userMapper->isAdmin()) @@ -177,7 +177,7 @@ public function add_news_line(array $news, int $count, string $lang_key, string { if ($count > 0) { $line = $this->translator->trans($lang_key, ['count' => $count]); - if ($add_url and !empty($url)) { + if ($add_url && ($url !== '' && $url !== '0')) { $line = '' . $line . ''; } $news[] = $line; @@ -198,7 +198,7 @@ public function add_news_line(array $news, int $count, string $lang_key, string * @param bool $add_url add html link around news * @return string[] */ - public function news(DateTimeInterface $start = null, DateTimeInterface $end = null, bool $exclude_img_cats = false, bool $add_url = false): array + public function news(?DateTimeInterface $start = null, ?DateTimeInterface $end = null, bool $exclude_img_cats = false, bool $add_url = false): array { $news = []; @@ -261,8 +261,9 @@ public function news(DateTimeInterface $start = null, DateTimeInterface $end = n public function get_recent_post_dates(int $max_dates, int $max_elements, int $max_cats): array { $dates = $this->imageMapper->getRepository()->getRecentPostedImages($max_dates, $this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums()); + $counter = count($dates); - for ($i = 0; $i < count($dates); $i++) { + for ($i = 0; $i < $counter; $i++) { if ($max_elements > 0) { // get some thumbnails ... $ids = []; foreach ($this->imageMapper->getRepository()->findRandomImages($max_elements, $this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums()) as $id) { @@ -388,12 +389,7 @@ public function check_sendmail_timeout(): bool public function get_user_notifications(string $action, array $check_key_list = [], ?bool $enabled_filter_value = null): array { if (in_array($action, ['subscribe', 'send'])) { - if ($action == 'send') { - $orders = ['n.last_send', 'u.username']; - } else { - $orders = ['u.username']; - } - + $orders = $action === 'send' ? ['n.last_send', 'u.username'] : ['u.username']; return $this->userMailNotificationRepository->findInfosForUsers(($action === 'send'), $enabled_filter_value, $check_key_list, $orders); } else { return []; @@ -417,12 +413,10 @@ public function begin_users_env_nbm(bool $is_to_send_mail = false): void // Init mail configuration if (!empty($this->conf['nbm_send_mail_as'])) { $this->env['send_as_name'] = $this->conf['nbm_send_mail_as']; + } elseif (!empty($this->conf['mail_sender_name'])) { + $this->env['send_as_name'] = $this->conf['mail_sender_name']; } else { - if (!empty($this->conf['mail_sender_name'])) { - $this->env['send_as_name'] = $this->conf['mail_sender_name']; - } else { - $this->env['send_as_name'] = $this->conf['gallery_title']; - } + $this->env['send_as_name'] = $this->conf['gallery_title']; } $this->env['send_as_mail_address'] = $this->userMapper->getWebmaster()->getMailAddress(); @@ -451,18 +445,18 @@ public function inc_mail_sent_failed($nbm_user): void public function display_counter_info(): void { + /** @phpstan-ignore-next-line */ if ($this->env['error_on_mail_count'] != 0) { $this->errors[] = $this->translator->trans('number_of_mails_not_sent', ['count' => $this->env['error_on_mail_count']]); - + /** @phpstan-ignore-next-line */ if ($this->env['sent_mail_count'] != 0) { $this->infos[] = $this->translator->trans('number_of_mails_sent', ['count' => $this->env['sent_mail_count']]); } + /** @phpstan-ignore-next-line */ + } elseif ($this->env['sent_mail_count'] == 0) { + $this->infos[] = $this->translator->trans('No mail to send.'); } else { - if ($this->env['sent_mail_count'] == 0) { - $this->infos[] = $this->translator->trans('No mail to send.'); - } else { - $this->infos[] = $this->translator->trans('number_of_mails_sent', ['count' => $this->env['sent_mail_count']]); - } + $this->infos[] = $this->translator->trans('number_of_mails_sent', ['count' => $this->env['sent_mail_count']]); } } @@ -608,19 +602,16 @@ public function subscribe_notification_by_mail($is_admin_request, $check_key_lis */ public function do_timeout_treatment($post_keyname, $check_key_treated = []): void { - if ($this->env['is_sendmail_timeout']) { - if (isset($_POST[$post_keyname])) { - $post_count = is_countable($_POST[$post_keyname]) ? count($_POST[$post_keyname]) : 0; - $treated_count = is_countable($check_key_treated) ? count($check_key_treated) : 0; - if ($treated_count != 0) { - $time_refresh = ceil((microtime(true) - $this->env['start_time']) * $post_count / $treated_count); - } else { - $time_refresh = 0; - } - $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated); - - $this->errors[] = $this->translator->trans('execution_timeout_in_seconds', ['count' => $time_refresh]); + if ($this->env['is_sendmail_timeout'] && isset($_POST[$post_keyname])) { + $post_count = is_countable($_POST[$post_keyname]) ? count($_POST[$post_keyname]) : 0; + $treated_count = is_countable($check_key_treated) ? count($check_key_treated) : 0; + if ($treated_count != 0) { + $time_refresh = ceil((microtime(true) - $this->env['start_time']) * $post_count / $treated_count); + } else { + $time_refresh = 0; } + $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated); + $this->errors[] = $this->translator->trans('execution_timeout_in_seconds', ['count' => $time_refresh]); } } @@ -651,7 +642,7 @@ public function insert_new_data_user_mail_notification(): void // On timeout simulate like tabsheet send if ($this->env['is_sendmail_timeout']) { $check_key_list = array_diff($check_key_list, $check_key_treated); - if (count($check_key_list) > 0) { + if ($check_key_list !== []) { $this->userMailNotificationRepository->deleteByCheckKeys($check_key_list); } } @@ -683,21 +674,18 @@ public function do_action_send_mail_notification($action = 'list_to_send', $chec // Check if exist news to list user or send mails if ((!$is_list_all_without_test) || ($is_action_send)) { - if (count($data_users) > 0) { + if ($data_users !== []) { if (!isset($customize_mail_content)) { $customize_mail_content = $this->conf['nbm_complementary_mail_content']; } - // Prepare message after change language if ($is_action_send) { $msg_break_timeout = $this->translator->trans('Time to send mail is limited. Others mails are skipped.'); } else { $msg_break_timeout = $this->translator->trans('Prepared time for list of users to send mail is limited. Others users are not listed.'); } - // Begin nbm users environment $this->begin_users_env_nbm($is_action_send); - foreach ($data_users as $nbm_user) { if ((!$is_action_send) && $this->check_sendmail_timeout()) { // Stop fill list on 'list_to_send', if the quota is override @@ -712,18 +700,15 @@ public function do_action_send_mail_notification($action = 'list_to_send', $chec if ($is_action_send) { $tpl_params = []; - // Fill return list of "treated" check_key for 'send' $return_list[] = $nbm_user->getCheckKey(); - $news = ''; if ($this->conf['nbm_send_detailed_content']) { $news = $this->news($nbm_user->getLastSend(), $now, false, $this->conf['nbm_send_html_mail']); - $exist_data = count($news) > 0; + $exist_data = $news !== []; } else { $exist_data = $this->news_exists($nbm_user->getLastSend(), $now); } - if ($exist_data) { $subject = $this->translator->trans('New photos added'); @@ -784,21 +769,16 @@ public function do_action_send_mail_notification($action = 'list_to_send', $chec $this->inc_mail_sent_failed($nbm_user); } } - } else { - if ($this->news_exists($nbm_user->getLastSend(), $now)) { - // Fill return list of "selected" users for 'list_to_send' - $return_list[] = $nbm_user; - } + } elseif ($this->news_exists($nbm_user->getLastSend(), $now)) { + // Fill return list of "selected" users for 'list_to_send' + $return_list[] = $nbm_user; } } - if ($is_action_send) { $this->display_counter_info(); } - } else { - if ($is_action_send) { - $this->errors[] = $this->translator->trans('No user to send notifications by mail.'); - } + } elseif ($is_action_send) { + $this->errors[] = $this->translator->trans('No user to send notifications by mail.'); } } else { // Quick List, don't check news diff --git a/src/Phyxo/Block/BlockManager.php b/src/Phyxo/Block/BlockManager.php index 21d778922..25df6c5aa 100644 --- a/src/Phyxo/Block/BlockManager.php +++ b/src/Phyxo/Block/BlockManager.php @@ -42,7 +42,7 @@ public function loadDefaultBlocks(): void /** * Triggers a notice that allows plugins of menu blocks to register the blocks. */ - public function loadRegisteredBlocks(EventDispatcherInterface $eventDispatcher = null): void + public function loadRegisteredBlocks(?EventDispatcherInterface $eventDispatcher = null): void { if (!is_null($eventDispatcher)) { $eventDispatcher->dispatch(new BlockEvent($this)); diff --git a/src/Phyxo/Block/DisplayBlock.php b/src/Phyxo/Block/DisplayBlock.php index f137a74eb..834d0519d 100644 --- a/src/Phyxo/Block/DisplayBlock.php +++ b/src/Phyxo/Block/DisplayBlock.php @@ -42,7 +42,7 @@ public function setPosition(int $position): void public function getTitle(): string { - if (isset($this->title)) { + if ($this->title !== null) { return $this->title; } else { return $this->registeredBlock->getName(); diff --git a/src/Phyxo/Block/RegisteredBlock.php b/src/Phyxo/Block/RegisteredBlock.php index 4c1d14967..d2cf0bec4 100644 --- a/src/Phyxo/Block/RegisteredBlock.php +++ b/src/Phyxo/Block/RegisteredBlock.php @@ -18,7 +18,7 @@ class RegisteredBlock { private $dataCallback; - public function __construct(private readonly string $id, private readonly string $name, private readonly string $owner, callable $dataCallback = null) + public function __construct(private readonly string $id, private readonly string $name, private readonly string $owner, ?callable $dataCallback = null) { $this->dataCallback = $dataCallback; } diff --git a/src/Phyxo/Conf.php b/src/Phyxo/Conf.php index bee790b8a..1a3d2a676 100644 --- a/src/Phyxo/Conf.php +++ b/src/Phyxo/Conf.php @@ -35,7 +35,7 @@ public function __construct(private readonly ConfigRepository $configRepository) public function init(string $default_config_file, string $user_config_file = ''): void { $this->loadFromFile($default_config_file); - if (!empty($user_config_file)) { + if ($user_config_file !== '' && $user_config_file !== '0') { $this->loadFromFile($user_config_file); } $this->loadFromDB(); @@ -54,7 +54,7 @@ public function loadFromFile($conf_file): void ob_end_clean(); /** @phpstan-ignore-next-line */ - if (count($conf) > 0) { + if ($conf !== []) { foreach ($conf as $key => $value) { $this->keys[self::FILE_PREFIX . $key] = ['value' => $value, 'type' => null]; } @@ -178,7 +178,7 @@ protected function deleteParam(string|array $params): void $params = [$params]; } - if (empty($params)) { + if ($params === []) { return; } diff --git a/src/Phyxo/Extension/Extensions.php b/src/Phyxo/Extension/Extensions.php index 48ff30397..afe4374f7 100644 --- a/src/Phyxo/Extension/Extensions.php +++ b/src/Phyxo/Extension/Extensions.php @@ -32,7 +32,7 @@ public function getJsonFromServer($url, $params = []) throw new Exception("Response is not readable"); } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -63,7 +63,7 @@ public function download($filename, $params = []) throw new Exception("Response is not readable"); } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -84,16 +84,14 @@ protected function extractZipFiles($zip_file, $main_file, $extract_path = ''): s $root = basename(dirname((string) $main_filepath)); // dirname($main_filepath) cannot be null throw Exception if needed $extract_path .= '/' . $root; - if (!empty($this->directory_pattern)) { - if (!preg_match($this->directory_pattern, $root)) { - throw new Exception(sprintf('Root directory (%s) of archive does not follow expected pattern %s', $root, $this->directory_pattern)); - } + if ($this->directory_pattern !== '' && $this->directory_pattern !== '0' && !preg_match($this->directory_pattern, $root)) { + throw new Exception(sprintf('Root directory (%s) of archive does not follow expected pattern %s', $root, $this->directory_pattern)); } // @TODO: use native zip library ; use arobase before if ($results = @$zip->extract(PCLZIP_OPT_PATH, $extract_path, PCLZIP_OPT_REMOVE_PATH, $root, PCLZIP_OPT_REPLACE_NEWER)) { $errors = array_filter($results, fn ($f) => ($f['status'] !== 'ok' && $f['status'] !== 'filtered') && $f['status'] !== 'already_a_directory'); - if (count($errors) > 0) { + if ($errors !== []) { throw new Exception("Error while extracting some files from archive"); } } else { diff --git a/src/Phyxo/Functions/Language.php b/src/Phyxo/Functions/Language.php index 3414b6841..c42cdf27a 100644 --- a/src/Phyxo/Functions/Language.php +++ b/src/Phyxo/Functions/Language.php @@ -20,7 +20,7 @@ public static function loadLanguageFile(string $filename, string $dirname = ''): { $content = ''; - if (!empty($dirname)) { + if ($dirname !== '' && $dirname !== '0') { $filename = $dirname . '/' . $filename; } @@ -64,7 +64,7 @@ public static function qualify_utf8(string $Str): int return -1; } // Does not match any model for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ? - if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) { + if ((++$i === strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) { return -1; } } diff --git a/src/Phyxo/Functions/Upload.php b/src/Phyxo/Functions/Upload.php index 2c166c8f1..6e0968450 100644 --- a/src/Phyxo/Functions/Upload.php +++ b/src/Phyxo/Functions/Upload.php @@ -63,17 +63,12 @@ public static function save_upload_form_config(array $data, array &$errors = [], continue; } if (is_bool($upload_form_config[$field]['default'])) { - if (isset($value)) { - $value = true; - } else { - $value = false; - } - + $value = isset($value); $updates[] = [ 'param' => $field, 'value' => true ]; - } elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) { + } elseif ($upload_form_config[$field]['can_be_null'] && empty($value)) { $updates[] = [ 'param' => $field, 'value' => null, @@ -83,7 +78,7 @@ public static function save_upload_form_config(array $data, array &$errors = [], $max = $upload_form_config[$field]['max']; $pattern = $upload_form_config[$field]['pattern']; - if (preg_match($pattern, (string) $value) and $value >= $min and $value <= $max) { + if (preg_match($pattern, (string) $value) && $value >= $min && $value <= $max) { $updates[] = [ 'param' => $field, 'value' => $value diff --git a/src/Phyxo/Functions/Utils.php b/src/Phyxo/Functions/Utils.php index 3a387c908..0eaa8733f 100644 --- a/src/Phyxo/Functions/Utils.php +++ b/src/Phyxo/Functions/Utils.php @@ -105,10 +105,10 @@ public static function convert_charset($str, $source_charset, $dest_charset) if ($source_charset == $dest_charset) { return $str; } - if ($source_charset == 'iso-8859-1' and $dest_charset == 'utf-8') { + if ($source_charset == 'iso-8859-1' && $dest_charset == 'utf-8') { return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); } - if ($source_charset == 'utf-8' and $dest_charset == 'iso-8859-1') { + if ($source_charset == 'utf-8' && $dest_charset == 'iso-8859-1') { return mb_convert_encoding($str, 'ISO-8859-1'); } if (function_exists('iconv')) { @@ -172,7 +172,7 @@ public static function getPrivacyLevelOptions(TranslatorInterface $translator, a if (0 == $level) { $label = $translator->trans('Everybody', [], $domain); } else { - if (strlen($label)) { + if (strlen($label) !== 0) { $label .= ', '; } $label .= $translator->trans('Level ' . $level, [], $domain); @@ -394,11 +394,7 @@ public static function getAdminClientCacheKeys(ManagerRegistry $managerRegistry, 'tags' => Tag::class, ]; - if (empty($requested)) { - $returned = array_keys($tables); - } else { - $returned = array_intersect($requested, array_keys($tables)); - } + $returned = $requested === [] ? array_keys($tables) : array_intersect($requested, array_keys($tables)); $keys = [ '_hash' => md5($base_url), @@ -421,12 +417,7 @@ public static function need_resize($image_filepath, $max_width, $max_height) // rotation must be applied to the resized photo, then we should test // invert width and height. $file_infos = self::image_infos($image_filepath); - - if ($file_infos['width'] > $max_width || $file_infos['height'] > $max_height) { - return true; - } - - return false; + return $file_infos['width'] > $max_width || $file_infos['height'] > $max_height; } public static function image_infos($path): array @@ -467,7 +458,7 @@ public static function convert_shorthand_notation_to_bytes($value) if (!is_null($multiply_by)) { $value = (int) substr((string) $value, 0, -1); - $value = $value * $multiply_by; + $value *= $multiply_by; } return $value; diff --git a/src/Phyxo/Functions/Ws/Category.php b/src/Phyxo/Functions/Ws/Category.php index 6b827190a..151fa99ab 100644 --- a/src/Phyxo/Functions/Ws/Category.php +++ b/src/Phyxo/Functions/Ws/Category.php @@ -55,7 +55,7 @@ public static function getImages($params, Server $service) } //-------------------------------------------------------- get the images - if (count($album_ids) > 0) { + if ($album_ids !== []) { foreach ($service->getImageMapper()->getRepository()->getImagesFromAlbums($album_ids, $params['per_page'], $params['per_page'] * $params['page']) as $image) { $images[] = $image->toArray(); } @@ -303,6 +303,7 @@ public static function setInfo($params, Server $service) if ($perform_update) { $service->getAlbumMapper()->getRepository()->addOrUpdateAlbum($album); } + return null; } /** @@ -331,6 +332,7 @@ public static function setRepresentative($params, Server $service) $service->getAlbumMapper()->getRepository()->addOrUpdateAlbum($album); $service->getManagerRegistry()->getRepository(UserCacheAlbum::class)->unsetUserRepresentativePictureForAlbum($params['category_id']); + return null; } /** @@ -370,7 +372,7 @@ public static function delete($params, Server $service) } if (count($album_ids) == 0) { - return; + return null; } foreach ($service->getAlbumMapper()->getRepository()->findBy(['id' => $album_ids]) as $album) { @@ -381,7 +383,7 @@ public static function delete($params, Server $service) $image_ids_to_delete[] = $image_album->getImage()->getId(); } $album->getImageAlbums()->clear(); - if (count($image_ids_to_delete) > 0) { + if ($image_ids_to_delete !== []) { $service->getImageMapper()->deleteElements($image_ids_to_delete, true); } } @@ -391,13 +393,14 @@ public static function delete($params, Server $service) foreach ($service->getImageMapper()->getRepository()->findBy(['storage_category_id' => $album_ids]) as $image) { $image_ids[] = $image->getId(); } - if (count($image_ids) > 0) { + if ($image_ids !== []) { $service->getImageMapper()->deleteElements($image_ids); } } $service->getAlbumMapper()->deleteAlbums($album_ids); $service->getAlbumMapper()->updateGlobalRank(); + return null; } /** @@ -460,9 +463,10 @@ public static function move($params, Server $service) $service->getAlbumMapper()->moveAlbums($category_ids, $params['parent'] === 0 ? null : $params['parent']); $service->getUserMapper()->invalidateUserCache(); - if (count($page['errors']) != 0) { + if ($page['errors'] !== []) { return new Error(403, implode('; ', $page['errors'])); } + return null; } /** diff --git a/src/Phyxo/Functions/Ws/Extension.php b/src/Phyxo/Functions/Ws/Extension.php index 7144c7a63..1af855a82 100644 --- a/src/Phyxo/Functions/Ws/Extension.php +++ b/src/Phyxo/Functions/Ws/Extension.php @@ -65,7 +65,7 @@ public static function update($params, Server $service) if (isset($extension->getDbPlugins()[$extension_id]) && $extension->getDbPlugins()[$extension_id]->getState() === Plugin::ACTIVE) { $extension->performAction('deactivate', $extension_id); - return; + return null; } $extension->performAction('update', $extension_id, $revision); @@ -155,11 +155,7 @@ public static function checkupdates($params, Server $service) $result['phyxo_need_update'] = $update->isCoreNeedUpdate(); - if (!empty($service->getConf()['updates_ignored'])) { - $updates_ignored = $service->getConf()['updates_ignored']; - } else { - $updates_ignored = []; - } + $updates_ignored = empty($service->getConf()['updates_ignored']) ? [] : $service->getConf()['updates_ignored']; if (!$update->isExtensionsNeedUpdate()) { $service->getConf()->addOrUpdateParam('updates_ignored', $update->checkExtensions($updates_ignored)); diff --git a/src/Phyxo/Functions/Ws/Image.php b/src/Phyxo/Functions/Ws/Image.php index d247acab5..85e57fcf3 100644 --- a/src/Phyxo/Functions/Ws/Image.php +++ b/src/Phyxo/Functions/Ws/Image.php @@ -105,7 +105,7 @@ public static function getInfo($params, Server $service) } usort($related_categories, '\Phyxo\Functions\Utils::global_rank_compare'); - if (count($related_categories) === 0) { + if ($related_categories === []) { return new Error(401, 'Access denied'); } @@ -230,7 +230,7 @@ public static function search($params, Server $service) $params['per_page'] ); - if (count($image_ids)) { + if ($image_ids !== []) { $image_ids = array_flip($image_ids); foreach ($service->getImageMapper()->getRepository()->findBy(['id' => $image_ids]) as $image) { $image_infos = $image->toArray(); @@ -267,6 +267,7 @@ public static function setPrivacyLevel($params, Server $service) $service->getImageMapper()->getRepository()->updateFieldForImages($params['image_id'], 'level', (int) $params['level']); $service->getUserMapper()->invalidateUserCache(); + return null; } /** @@ -357,6 +358,7 @@ public static function addChunk($params, Server $service) 'an error has occured while writting chunk ' . $params['position'] . ' for ' . $params['type'] ); } + return null; } /** @@ -419,6 +421,7 @@ public static function addFile($params, Server $service) $image->getMd5sum() // we force the md5sum to remain the same ); $service->getTagMapper()->sync_metadata([$image_id]); + return null; } /** @@ -550,10 +553,8 @@ public static function addSimple($params, Server $service) return new Error(405, 'The image (file) is missing'); } - if ($params['image_id'] > 0) { - if (is_null($service->getImageMapper()->getRepository()->find($params['image_id']))) { - return new Error(404, 'image_id not found'); - } + if ($params['image_id'] > 0 && is_null($service->getImageMapper()->getRepository()->find($params['image_id']))) { + return new Error(404, 'image_id not found'); } $image_id = self::addUploadedFile( @@ -644,7 +645,7 @@ public static function upload($params, Server $service) // Get a file name if (isset($_REQUEST["name"])) { $fileName = $_REQUEST["name"]; - } elseif (!empty($_FILES)) { + } elseif ($_FILES !== []) { $fileName = $_FILES["file"]["name"]; } else { $fileName = uniqid("file_"); @@ -657,23 +658,20 @@ public static function upload($params, Server $service) $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; // Open temp file - if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) { + if (!$out = @fopen("{$filePath}.part", $chunks !== 0 ? "ab" : "wb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } - if (!empty($_FILES)) { + if ($_FILES !== []) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } - // Read binary input stream and append it to temp file if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } - } else { - if (!$in = @fopen("php://input", "rb")) { - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); - } + } elseif (!$in = @fopen("php://input", "rb")) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } while ($buff = fread($in, 4096)) { @@ -719,6 +717,7 @@ public static function upload($params, Server $service) ] ]; } + return null; } /** @@ -817,11 +816,7 @@ public static function checkFiles($params, Server $service) } if (isset($compare_type)) { - if (md5_file($image->getPath()) != $params[$compare_type . '_sum']) { - $ret[$compare_type] = 'differs'; - } else { - $ret[$compare_type] = 'equals'; - } + $ret[$compare_type] = md5_file($image->getPath()) != $params[$compare_type . '_sum'] ? 'differs' : 'equals'; } return $ret; @@ -856,15 +851,11 @@ public static function setRelatedTags($params, Server $service) $removed_tags = array_diff($current_tags, $params['tags']); $new_tags = array_diff($params['tags'], $current_tags); - if (count($removed_tags) > 0) { - if ($service->getSecurity()->isGranted(TagVoter::DELETE, $image) == false) { - return new Error(403, 'You are not allowed to delete tags'); - } + if (count($removed_tags) > 0 && $service->getSecurity()->isGranted(TagVoter::DELETE, $image) == false) { + return new Error(403, 'You are not allowed to delete tags'); } - if (count($new_tags) > 0) { - if ($service->getSecurity()->isGranted(TagVoter::ADD, $image) == false) { - return new Error(403, 'You are not allowed to add tags'); - } + if (count($new_tags) > 0 && $service->getSecurity()->isGranted(TagVoter::ADD, $image) == false) { + return new Error(403, 'You are not allowed to add tags'); } try { @@ -876,7 +867,7 @@ public static function setRelatedTags($params, Server $service) } } else { // if publish_tags_immediately (or delete_tags_immediately) is not set we consider its value is 1 - if (count($removed_tags) > 0) { + if ($removed_tags !== []) { $removed_tags_ids = $service->getTagMapper()->getTagsIds($removed_tags); if (isset($service->getConf()['delete_tags_immediately']) && $service->getConf()['delete_tags_immediately'] == 0) { $service->getTagMapper()->toBeValidatedTags($image, $removed_tags_ids, $service->getUserMapper()->getUser(), ImageTag::STATUS_TO_DELETE); @@ -885,7 +876,7 @@ public static function setRelatedTags($params, Server $service) } } - if (count($new_tags) > 0) { + if ($new_tags !== []) { $new_tags_ids = $service->getTagMapper()->getTagsIds($new_tags); if (isset($service->getConf()['publish_tags_immediately']) && $service->getConf()['publish_tags_immediately'] == 0) { $service->getTagMapper()->toBeValidatedTags($image, $new_tags_ids, $service->getUserMapper()->getUser(), ImageTag::STATUS_TO_ADD); @@ -897,6 +888,7 @@ public static function setRelatedTags($params, Server $service) } catch (Exception) { return new Error(500, '[ws_images_setRelatedTags] Something went wrong when updating tags'); } + return null; } /** @@ -961,7 +953,7 @@ public static function setInfo($params, Server $service) $service, $params['image_id'], $params['categories'], - ('replace' == $params['multiple_value_mode'] ? true : false) + ('replace' == $params['multiple_value_mode']) ); } @@ -992,6 +984,7 @@ public static function setInfo($params, Server $service) } $service->getUserMapper()->invalidateUserCache(); + return null; } /** @@ -1038,10 +1031,8 @@ public static function checkUpload($params, Server $service) if (!is_writable(dirname((string) $service->getUploadDir()))) { $message = sprintf('Create the "%s" directory at the root of your Phyxo installation', basename((string) $service->getUploadDir())); } - } else { - if (!is_writable($service->getUploadDir())) { - $message = sprintf('Give write access (chmod 777) to "%s" directory at the root of your Phyxo installation', basename((string) $service->getUploadDir())); - } + } elseif (!is_writable($service->getUploadDir())) { + $message = sprintf('Give write access (chmod 777) to "%s" directory at the root of your Phyxo installation', basename((string) $service->getUploadDir())); } return ['message' => $message, 'ready_for_upload' => $message === '']; @@ -1085,7 +1076,7 @@ protected static function addImageAlbumRelations(Server $service, int $image_id, $album_ids = array_unique($album_ids); - if (count($album_ids) === 0) { + if ($album_ids === []) { return new Error( 500, '[\Phyxo\Functions\Ws\Images::addImageAlbumRelations] there is no category defined in "' . $categories_string . '"' @@ -1118,6 +1109,7 @@ protected static function addImageAlbumRelations(Server $service, int $image_id, } $service->getAlbumMapper()->updateAlbums($album_ids); + return null; } /** @@ -1157,6 +1149,7 @@ protected static function merge_chunks(string $output_filepath, string $original unlink($chunk); } + return null; } /** @@ -1200,11 +1193,7 @@ protected static function addUploadedFile(Server $service, string $source_filepa // TODO // * check md5sum (already exists?) - if (isset($original_md5sum)) { - $md5sum = $original_md5sum; - } else { - $md5sum = md5_file($source_filepath); - } + $md5sum = $original_md5sum ?? md5_file($source_filepath); $fs = new Filesystem(); $file_path = null; @@ -1283,7 +1272,7 @@ protected static function addUploadedFile(Server $service, string $source_filepa if (isset($image_id)) { $image = $service->getImageMapper()->getRepository()->find($image_id); - $image->setFile(!empty($original_filename) ? $original_filename : basename((string) $file_path)); + $image->setFile($original_filename === '' || $original_filename === '0' ? basename((string) $file_path) : $original_filename); $image->setFilesize($filesize); $image->setWidth($width); $image->setHeight($height); @@ -1297,7 +1286,7 @@ protected static function addUploadedFile(Server $service, string $source_filepa $service->getImageMapper()->getRepository()->addOrUpdateImage($image); } else { $image = new EntityImage(); - $image->setFile(!empty($original_filename) ? $original_filename : basename((string) $file_path)); + $image->setFile($original_filename === '' || $original_filename === '0' ? basename((string) $file_path) : $original_filename); $image->setName(Utils::get_name_from_file($image->getFile())); $image->setDateAvailable($now); $image->setPath(preg_replace('#^' . preg_quote(dirname((string) $upload_dir)) . '#', '.', realpath($file_path))); @@ -1319,7 +1308,7 @@ protected static function addUploadedFile(Server $service, string $source_filepa $image_id = $service->getImageMapper()->getRepository()->addOrUpdateImage($image); } - if (count($categories) > 0) { + if ($categories !== []) { $service->getAlbumMapper()->associateImagesToAlbums([$image_id], $categories); } diff --git a/src/Phyxo/Functions/Ws/Main.php b/src/Phyxo/Functions/Ws/Main.php index a23e2b5cf..adcebfdcf 100644 --- a/src/Phyxo/Functions/Ws/Main.php +++ b/src/Phyxo/Functions/Ws/Main.php @@ -201,7 +201,9 @@ public static function stdGetUrls(Image $image, Server $service) $derivatives_arr = []; foreach ($derivatives as $type => $derivative) { $size = $derivative->getSize(); - $size != null or $size = [null, null]; + if ($size == null) { + $size = [null, null]; + } $derivatives_arr[$type] = [ 'url' => $service->getRouter()->generate('admin_media', ['path' => $image->getPathBasename(), 'derivative' => $derivative->getUrlType(), 'image_extension' => $image->getExtension()]), 'width' => $size[0], diff --git a/src/Phyxo/Functions/Ws/Permission.php b/src/Phyxo/Functions/Ws/Permission.php index 06bed25a5..81819f0c7 100644 --- a/src/Phyxo/Functions/Ws/Permission.php +++ b/src/Phyxo/Functions/Ws/Permission.php @@ -64,11 +64,7 @@ public static function getList($params, Server $service) // indirect users $album_ids = []; if (!empty($params['cat_id'])) { - if (is_array($params['cat_id'])) { - $album_ids = $params['cat_id']; - } else { - $album_ids = [$params['cat_id']]; - } + $album_ids = is_array($params['cat_id']) ? $params['cat_id'] : [$params['cat_id']]; } foreach ($service->getUserMapper()->getRepository()->findWithAlbumsAccess($album_ids) as $user) { $permissions[$album->getId()]['users_indirect'][] = $user->getId(); @@ -82,23 +78,18 @@ public static function getList($params, Server $service) // filter by group and user foreach ($permissions as $album_id => &$album) { - if (!empty($params['group_id'])) { - if (empty($album['groups']) || count(array_intersect($album['groups'], $params['group_id'])) === 0) { - unset($permissions[$album_id]); - continue; - } + if (!empty($params['group_id']) && (empty($album['groups']) || count(array_intersect($album['groups'], $params['group_id'])) === 0)) { + unset($permissions[$album_id]); + continue; } - if (!empty($params['user_id'])) { - if ((empty($album['users_indirect']) || count(array_intersect($album['users_indirect'], $params['user_id'])) === 0) - && (empty($album['users']) || count(array_intersect($album['users'], $params['user_id'])) === 0)) { - unset($permissions[$album_id]); - continue; - } + if (!empty($params['user_id']) && ((empty($album['users_indirect']) || count(array_intersect($album['users_indirect'], $params['user_id'])) === 0) && (empty($album['users']) || count(array_intersect($album['users'], $params['user_id'])) === 0))) { + unset($permissions[$album_id]); + continue; } - $album['groups'] = !empty($album['groups']) ? array_values(array_unique($album['groups'])) : []; - $album['users'] = !empty($album['users']) ? array_values(array_unique($album['users'])) : []; - $album['users_indirect'] = !empty($album['users_indirect']) ? array_values(array_unique($album['users_indirect'])) : []; + $album['groups'] = empty($album['groups']) ? [] : array_values(array_unique($album['groups'])); + $album['users'] = empty($album['users']) ? [] : array_values(array_unique($album['users'])); + $album['users_indirect'] = empty($album['users_indirect']) ? [] : array_values(array_unique($album['users_indirect'])); } return ['categories' => array_values($permissions)]; @@ -133,14 +124,14 @@ public static function add($params, Server $service) foreach ($service->getAlbumMapper()->findByIdsAndStatus($album_ids, Album::STATUS_PRIVATE) as $album) { $need_update = false; - if (count($groups) > 0) { + if ($groups !== []) { $need_update = true; foreach ($groups as $group) { $album->addGroupAccess($group); } } - if (count($users) > 0) { + if ($users !== []) { $need_update = true; foreach ($users as $user) { $album->addUserAcccess($user); diff --git a/src/Phyxo/Functions/Ws/Plugin.php b/src/Phyxo/Functions/Ws/Plugin.php index db10605d1..d6b5dca26 100644 --- a/src/Phyxo/Functions/Ws/Plugin.php +++ b/src/Phyxo/Functions/Ws/Plugin.php @@ -31,11 +31,7 @@ public static function getList($params, Server $service) $plugin_list = []; foreach ($plugins->getFsPlugins() as $plugin_id => $fs_plugin) { - if (isset($plugins->getDbPlugins()[$plugin_id])) { - $state = $plugins->getDbPlugins()[$plugin_id]['state']; - } else { - $state = 'uninstalled'; - } + $state = isset($plugins->getDbPlugins()[$plugin_id]) ? $plugins->getDbPlugins()[$plugin_id]['state'] : 'uninstalled'; $plugin_list[] = [ 'id' => $plugin_id, @@ -62,8 +58,9 @@ public static function performAction($params, Server $service) $plugins->setRootPath($service->getParams()->get('plugins_dir')); $error = $plugins->performAction($params['action'], $params['plugin']); - if (!empty($error)) { + if ($error !== '' && $error !== '0') { return new Error(500, $error); } + return null; } } diff --git a/src/Phyxo/Functions/Ws/Rate.php b/src/Phyxo/Functions/Ws/Rate.php index 3f8b9e68e..d14ca6594 100644 --- a/src/Phyxo/Functions/Ws/Rate.php +++ b/src/Phyxo/Functions/Ws/Rate.php @@ -27,8 +27,8 @@ public function delete($params, Server $service) { $changes = $service->getManagerRegistry()->getRepository(EntityRate::class)->deleteWithConditions( $params['user_id'], - !empty($params['anonymous_id']) ? $params['anonymous_id'] : null, - !empty($params['image_id']) ? $params['image_id'] : null + empty($params['anonymous_id']) ? null : $params['anonymous_id'], + empty($params['image_id']) ? null : $params['image_id'] ); if ($changes) { diff --git a/src/Phyxo/Functions/Ws/Session.php b/src/Phyxo/Functions/Ws/Session.php index 1bc42596c..bb2f6dc20 100644 --- a/src/Phyxo/Functions/Ws/Session.php +++ b/src/Phyxo/Functions/Ws/Session.php @@ -27,7 +27,7 @@ class Session */ public static function login($params, Server $service) { - if ($service->getAppUserService()->getUser() !== null) { + if ($service->getAppUserService()->getUser() instanceof User) { return true; } else { return new Error(999, 'Invalid username/password'); diff --git a/src/Phyxo/Functions/Ws/Tag.php b/src/Phyxo/Functions/Ws/Tag.php index 59cc8511e..f3cb53c99 100644 --- a/src/Phyxo/Functions/Ws/Tag.php +++ b/src/Phyxo/Functions/Ws/Tag.php @@ -96,7 +96,7 @@ public static function getImages($params, Server $service) $image_tag_map = []; // build list of image ids with associated tags per image - if (count($image_ids) > 0 && !$params['tag_mode_and']) { + if ($image_ids !== [] && !$params['tag_mode_and']) { $image_tag_map = []; foreach ($service->getTagMapper()->getRepository()->findImageTags($tag_ids, $image_ids) as $tag) { $image_tag_map[$tag->getImage()->getId()][] = $tag->getId(); @@ -104,7 +104,7 @@ public static function getImages($params, Server $service) } $images = []; - if (!empty($image_ids)) { + if ($image_ids !== []) { $rank_of = array_flip($image_ids); foreach ($service->getImageMapper()->getRepository()->findBy(['id' => $image_ids]) as $image) { @@ -180,8 +180,9 @@ public static function tagsList(array $tags, $params, Server $service) } else { usort($tags, [$service->getTagMapper(), 'alphaCompare']); } + $counter = count($tags); - for ($i = 0; $i < count($tags); $i++) { + for ($i = 0; $i < $counter; $i++) { if (!empty($params['sort_by_counter'])) { $tags[$i]['counter'] = (int) $tags[$i]['counter']; } diff --git a/src/Phyxo/Functions/Ws/Theme.php b/src/Phyxo/Functions/Ws/Theme.php index 5ea98a752..9323da7ea 100644 --- a/src/Phyxo/Functions/Ws/Theme.php +++ b/src/Phyxo/Functions/Ws/Theme.php @@ -30,7 +30,7 @@ public static function performAction(array $params, Server $service) $themes = new Themes($service->getManagerRegistry()->getRepository(EntityTheme::class), $service->getUserMapper()); $errors = $themes->performAction($params['action'], $params['theme']); - if (!empty($errors)) { + if ($errors !== '' && $errors !== '0') { return new Error(500, $errors); } diff --git a/src/Phyxo/Functions/Ws/User.php b/src/Phyxo/Functions/Ws/User.php index a4ba63c9c..3ffe4ea81 100644 --- a/src/Phyxo/Functions/Ws/User.php +++ b/src/Phyxo/Functions/Ws/User.php @@ -119,7 +119,7 @@ public static function getList($params, Server $service) $users[$user['id']] = $user; } - if (count($users) > 0) { + if ($users !== []) { foreach ($users as $cur_user) { $fmt = new IntlDateFormatter($service->getUserMapper()->getUser()->getLocale(), IntlDateFormatter::FULL, IntlDateFormatter::NONE); @@ -141,7 +141,7 @@ public static function getList($params, Server $service) $history_ids[] = $history->getId(); } - if (count($history_ids) > 0) { + if ($history_ids !== []) { foreach ($service->getManagerRegistry()->getRepository(History::class)->findBy(['id' => $history_ids]) as $history) { $last_visit = $history->getDate(); $last_visit->setTime(...explode(':', $history->getTime()->format('h:i:s'))); @@ -171,10 +171,8 @@ public static function getList($params, Server $service) */ public static function add($params, Server $service) { - if ($service->getConf()['double_password_type_in_admin']) { - if ($params['password'] != $params['password_confirm']) { - return new Error(Server::WS_ERR_INVALID_PARAM, 'The passwords do not match'); - } + if ($service->getConf()['double_password_type_in_admin'] && $params['password'] != $params['password_confirm']) { + return new Error(Server::WS_ERR_INVALID_PARAM, 'The passwords do not match'); } try { @@ -368,7 +366,7 @@ public static function setInfo($params, Server $service) $service->getManagerRegistry()->getRepository(UserInfos::class)->updateFieldForUsers('status', $update_status, $params['user_id_for_status']); } - if (count($updates_infos) > 0) { + if ($updates_infos !== []) { $service->getManagerRegistry()->getRepository(UserInfos::class)->updateFieldsForUsers($updates_infos, $params['user_id']); } diff --git a/src/Phyxo/Image/DerivativeImage.php b/src/Phyxo/Image/DerivativeImage.php index 308bd5024..52187770c 100644 --- a/src/Phyxo/Image/DerivativeImage.php +++ b/src/Phyxo/Image/DerivativeImage.php @@ -65,7 +65,7 @@ public function getSize(): array $rotation = intval($this->image->getRotation()) % 4; // 1 or 5 => 90 clockwise // 3 or 7 => 270 clockwise - if ($rotation % 2) { + if ($rotation % 2 !== 0) { $width = $this->image->getHeight(); $height = $this->image->getWidth(); } @@ -85,7 +85,7 @@ public function getUrlSize(): string $this->params->add_url_tokens($tokens); } - return sprintf('%s', implode('', $tokens)); + return implode('', $tokens); } /** @@ -94,7 +94,7 @@ public function getUrlSize(): string public function getLiteralSize(): string { $size = $this->getSize(); - if (!$size) { + if ($size === []) { return ''; } @@ -111,7 +111,7 @@ public function relativeThumbInfos(): array private function buildInfos(): array { - if (count($this->getSize()) > 0 && $this->params->is_identity($this->getSize())) { + if ($this->getSize() !== [] && $this->params->is_identity($this->getSize())) { // the source image is smaller than what we should do - we do not upsample if (!$this->params->will_watermark($this->getSize(), $this->image_std_params) && !$this->image->getRotation()) { // no watermark, no rotation required -> we will use the source image @@ -124,7 +124,8 @@ private function buildInfos(): array } $defined_types = array_keys($this->image_std_params->getDefinedTypeMap()); - for ($i = 0; $i < count($defined_types); $i++) { + $counter = count($defined_types); + for ($i = 0; $i < $counter; $i++) { if ($defined_types[$i] == $this->params->type) { for ($i--; $i >= 0; $i--) { $smaller = $this->image_std_params->getByType($defined_types[$i]); diff --git a/src/Phyxo/Image/DerivativeParams.php b/src/Phyxo/Image/DerivativeParams.php index 23d0ecce9..70132a89a 100644 --- a/src/Phyxo/Image/DerivativeParams.php +++ b/src/Phyxo/Image/DerivativeParams.php @@ -66,7 +66,7 @@ public function max_height(): int */ public function is_identity(array $in_size): bool { - return !($in_size[0] > $this->sizing->ideal_size[0] || $in_size[1] > $this->sizing->ideal_size[1]); + return $in_size[0] <= $this->sizing->ideal_size[0] && $in_size[1] <= $this->sizing->ideal_size[1]; } public function will_watermark($out_size, ImageStandardParams $image_std_params): bool diff --git a/src/Phyxo/Image/ImageOptimizer.php b/src/Phyxo/Image/ImageOptimizer.php index 08970244c..5ef210e71 100644 --- a/src/Phyxo/Image/ImageOptimizer.php +++ b/src/Phyxo/Image/ImageOptimizer.php @@ -185,7 +185,7 @@ public function mainResize( $this->resize($resizeDimensions['width'], $resizeDimensions['height']); - if (!empty($rotation)) { + if ($rotation !== null && $rotation !== 0) { $this->rotate($rotation); } diff --git a/src/Phyxo/Image/ImageStandardParams.php b/src/Phyxo/Image/ImageStandardParams.php index a6b599f5b..21c5fde2d 100644 --- a/src/Phyxo/Image/ImageStandardParams.php +++ b/src/Phyxo/Image/ImageStandardParams.php @@ -235,8 +235,9 @@ protected function buildMaps() } $this->all_type_map = $this->type_map; + $counter = count($this->all_types); - for ($i = 0; $i < count($this->all_types); $i++) { + for ($i = 0; $i < $counter; $i++) { $tocheck = $this->all_types[$i]; if (!isset($this->type_map[$tocheck])) { for ($j = $i - 1; $j >= 0; $j--) { diff --git a/src/Phyxo/Language/Languages.php b/src/Phyxo/Language/Languages.php index 24457d760..b3311f99a 100644 --- a/src/Phyxo/Language/Languages.php +++ b/src/Phyxo/Language/Languages.php @@ -41,7 +41,7 @@ public function setRootPath(string $languages_root_path) /** * Perform requested actions */ - public function performAction(string $action, string $language_id, string $revision_id = null) + public function performAction(string $action, string $language_id, ?string $revision_id = null) { if (!$this->db_languages_retrieved) { $this->getDbLanguages(); @@ -159,7 +159,8 @@ public function getFsLanguages(): array if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $language_data, $val)) { $language['author uri'] = trim($val[1]); } - if (!empty($language['uri']) and strpos($language['uri'], 'extension_view.php?eid=')) { + /** @phpstan-ignore-next-line */ + if (isset($language['uri']) && ($language['uri'] !== '' && $language['uri'] !== '0') && strpos($language['uri'], 'extension_view.php?eid=')) { [, $extension] = explode('extension_view.php?eid=', $language['uri']); if (is_numeric($extension)) { $language['extension'] = $extension; @@ -216,10 +217,10 @@ public function getServerLanguages(string $pem_category, string $phyxo_version, } } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } - if (empty($versions_to_check)) { + if ($versions_to_check === []) { return []; } @@ -239,7 +240,7 @@ public function getServerLanguages(string $pem_category, string $phyxo_version, 'lang' => 'en_GB', // @TODO: inject user language 'get_nb_downloads' => 'true', ]); - if (!empty($languages_to_check)) { + if ($languages_to_check !== []) { if ($new) { $get_data['extension_exclude'] = implode(',', $languages_to_check); } else { @@ -260,7 +261,7 @@ public function getServerLanguages(string $pem_category, string $phyxo_version, } uasort($this->server_languages, $this->extensionNameCompare(...)); } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } $this->server_languages_retrieved = true; @@ -283,7 +284,7 @@ public function extractLanguageFiles(string $action, int $revision) try { $this->download($archive, $get_data); } catch (Exception $e) { - throw new Exception("Cannot download language archive"); + throw new Exception("Cannot download language archive", $e->getCode(), $e); } try { @@ -295,7 +296,7 @@ public function extractLanguageFiles(string $action, int $revision) $this->performAction('update', $language_id); } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } finally { unlink($archive); } @@ -320,7 +321,7 @@ protected function extractLanguageZipFiles(string $zip_file, string $extract_pat // @TODO: use native zip library ; use arobase before if ($results = @$zip->extract(PCLZIP_OPT_PATH, $extract_path, PCLZIP_OPT_REMOVE_PATH, $extract_path, PCLZIP_OPT_REPLACE_NEWER)) { $errors = array_filter($results, fn ($f) => ($f['status'] !== 'ok' && $f['status'] !== 'filtered') && $f['status'] !== 'already_a_directory'); - if (count($errors) > 0) { + if ($errors !== []) { throw new Exception("Error while extracting some files from archive"); } } else { diff --git a/src/Phyxo/MenuBar.php b/src/Phyxo/MenuBar.php index 8befab2b6..b6094bc92 100644 --- a/src/Phyxo/MenuBar.php +++ b/src/Phyxo/MenuBar.php @@ -101,7 +101,7 @@ protected function linksBlock() $block->data[] = $tpl_var; } - if (!empty($block->data)) { + if ($block->data !== []) { $block->template = 'menubar_links'; } } diff --git a/src/Phyxo/Plugin/Plugins.php b/src/Phyxo/Plugin/Plugins.php index e118de0f4..32b6ac050 100644 --- a/src/Phyxo/Plugin/Plugins.php +++ b/src/Phyxo/Plugin/Plugins.php @@ -70,7 +70,7 @@ private function buildMaintainClass($plugin_id) /** * Perform requested actions */ - public function performAction(string $action, string $plugin_id, int $revision = null): string + public function performAction(string $action, string $plugin_id, ?int $revision = null): string { if (!$this->db_plugins_retrieved) { $this->getDbPlugins(); @@ -232,7 +232,7 @@ public function getDbPlugins(string $state = '', string $id = ''): array $this->db_plugins_retrieved = true; } - if (!empty($id)) { + if ($id !== '' && $id !== '0') { return $this->db_plugins[$id] ?? []; } else { return $this->db_plugins; @@ -315,7 +315,7 @@ public function getServerPlugins(string $pem_category, string $core_version, $ne 'get_nb_downloads' => 'true', ]; - if (!empty($plugins_to_check)) { + if ($plugins_to_check !== []) { if ($new) { $get_data['extension_exclude'] = implode(',', $plugins_to_check); } else { @@ -333,7 +333,7 @@ public function getServerPlugins(string $pem_category, string $core_version, $ne $this->server_plugins[$plugin['extension_id']] = $plugin; } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } $this->server_plugins_retrieved = true; @@ -391,7 +391,7 @@ public function getIncompatiblePlugins(string $pem_category, string $core_versio return $incompatible_plugins; } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -433,14 +433,14 @@ public function extractPluginFiles(string $action, int $revision) try { $this->download($archive, $get_data); } catch (Exception $e) { - throw new Exception("Cannot download plugin file"); + throw new Exception("Cannot download plugin file", $e->getCode(), $e); } $extract_path = $this->plugins_root_path; try { $this->extractZipFiles($archive, self::CONFIG_FILE, $extract_path); } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } finally { unlink($archive); } diff --git a/src/Phyxo/Theme/Themes.php b/src/Phyxo/Theme/Themes.php index f996b0040..00d87caae 100644 --- a/src/Phyxo/Theme/Themes.php +++ b/src/Phyxo/Theme/Themes.php @@ -185,7 +185,7 @@ public function getChildrenThemes($theme_id) $children = []; foreach ($this->getFsThemes() as $test_child) { - if (isset($test_child['parent']) and $test_child['parent'] == $theme_id) { + if (isset($test_child['parent']) && $test_child['parent'] == $theme_id) { $children[] = $test_child['name']; } } @@ -321,10 +321,10 @@ public function getServerThemes(string $pem_category, string $phyxo_version, $ne } } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } - if (empty($versions_to_check)) { + if ($versions_to_check === []) { return []; } @@ -348,7 +348,7 @@ public function getServerThemes(string $pem_category, string $phyxo_version, $ne ] ); - if (!empty($themes_to_check)) { + if ($themes_to_check !== []) { if ($new) { $get_data['extension_exclude'] = implode(',', $themes_to_check); } else { @@ -365,7 +365,7 @@ public function getServerThemes(string $pem_category, string $phyxo_version, $ne $this->server_themes[$theme['extension_id']] = $theme; } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } $this->server_themes_retrieved = true; } @@ -410,14 +410,14 @@ public function extractThemeFiles(string $action, int $revision) try { $this->download($archive, $get_data); } catch (Exception $e) { - throw new Exception("Cannot download theme archive"); + throw new Exception("Cannot download theme archive", $e->getCode(), $e); } $extract_path = $this->themes_root_path; try { $this->extractZipFiles($archive, self::CONFIG_FILE, $extract_path); } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } finally { unlink($archive); } diff --git a/src/Phyxo/Update/Updates.php b/src/Phyxo/Update/Updates.php index 363308ab7..5f3e60850 100644 --- a/src/Phyxo/Update/Updates.php +++ b/src/Phyxo/Update/Updates.php @@ -74,7 +74,7 @@ public function getAllVersions() return false; } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -121,7 +121,7 @@ public function download($zip_file) file_put_contents($zip_file, $response->getContent()); } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -145,7 +145,7 @@ public function upgrade($zip_file) continue; } } - if (count($not_writable) > 0) { + if ($not_writable !== []) { $message = 'Some files or directories are not writable'; $message .= '
' . implode("\n", $not_writable) . '
'; throw new Exception($message); @@ -193,10 +193,10 @@ public function getServerExtensions() } } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } - if (empty($versions_to_check)) { + if ($versions_to_check === []) { return false; } @@ -222,7 +222,7 @@ public function getServerExtensions() $url .= '?' . http_build_query($get_data, '', '&'); $post_data = []; - if (!empty($ext_to_check)) { + if ($ext_to_check !== []) { $post_data['extension_include'] = implode(',', array_keys($ext_to_check)); } @@ -256,7 +256,7 @@ public function getServerExtensions() $this->checkMissingExtensions($ext_to_check); return []; } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } } @@ -270,7 +270,7 @@ public function checkCoreUpgrade() $all_versions = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR); } } catch (Exception $e) { - throw new Exception($e->getMessage()); + throw new Exception($e->getMessage(), $e->getCode(), $e); } if (!empty($all_versions)) { $new_version = trim((string) $all_versions[0]['version']); @@ -322,6 +322,7 @@ public function checkUpdatedExtensions(array $updates_ignored = []) } } } + return null; } protected function checkMissingExtensions($missing) @@ -329,8 +330,7 @@ protected function checkMissingExtensions($missing) foreach ($missing as $id => $type) { $default = 'default_' . $type; foreach ($this->getType($type)->getFsExtensions() as $ext_id => $ext) { - if (isset($ext['extension']) and $id == $ext['extension'] - and !in_array($ext_id, $this->$default)) { + if (isset($ext['extension']) && $id == $ext['extension'] && !in_array($ext_id, $this->$default)) { $this->missing[$type][] = $ext; break; } diff --git a/src/Phyxo/Upgrade.php b/src/Phyxo/Upgrade.php index 0e0727632..e06b9fe77 100644 --- a/src/Phyxo/Upgrade.php +++ b/src/Phyxo/Upgrade.php @@ -21,7 +21,7 @@ public static function getAvailableUpgradeIds(string $root_dir): array if ($contents = opendir($upgrades_path)) { while (($node = readdir($contents)) !== false) { - if (is_file($upgrades_path . '/' . $node) and preg_match('/^(.*?)-database\.php$/', $node, $match)) { + if (is_file($upgrades_path . '/' . $node) && preg_match('/^(.*?)-database\.php$/', $node, $match)) { $available_upgrade_ids[] = $match[1]; } } diff --git a/src/Phyxo/Ws/Server.php b/src/Phyxo/Ws/Server.php index ec0aff505..2d4f4aba9 100644 --- a/src/Phyxo/Ws/Server.php +++ b/src/Phyxo/Ws/Server.php @@ -315,16 +315,13 @@ public function run(Request $request) if ($request->getContentTypeFormat() === 'json') { $request_params = json_decode($request->getContent(), true); - if (json_last_error() !== JSON_ERROR_NONE) { throw new BadRequestHttpException('invalid json body: ' . json_last_error_msg()); } + } elseif ($request->isMethod('POST')) { + $request_params = $request->request->all(); } else { - if ($request->isMethod('POST')) { - $request_params = $request->request->all(); - } else { - $request_params = $request->query->all(); - } + $request_params = $request->query->all(); } foreach ($request_params as $name => $value) { @@ -370,10 +367,6 @@ public function run(Request $request) */ public function addMethod(string $methodName, $callback, array $params = [], string $description = '', array $options = []) { - if (!is_array($params)) { - $params = []; - } - if (range(0, count($params) - 1) === array_keys($params)) { $params = array_flip($params); } @@ -433,9 +426,9 @@ public static function isPost() //Receive the RAW post data. $content = trim(file_get_contents("php://input")); - return !empty($content); + return $content !== '' && $content !== '0'; } else { - return !empty($_POST); + return $_POST !== []; } } @@ -443,10 +436,8 @@ public static function makeArrayParam(&$param) { if ($param == null) { $param = []; - } else { - if (!is_array($param)) { - $param = [$param]; - } + } elseif (!is_array($param)) { + $param = [$param]; } } @@ -479,8 +470,7 @@ public static function checkType(&$param, $type, $name) unset($value); } elseif (self::hasFlag($type, self::WS_TYPE_FLOAT)) { foreach ($param as &$value) { - if (($value = filter_var($value, FILTER_VALIDATE_FLOAT)) === false - or (isset($opts['options']['min_range']) and $value < $opts['options']['min_range'])) { + if ($value = filter_var($value, FILTER_VALIDATE_FLOAT) === false || isset($opts['options']['min_range']) && $value < $opts['options']['min_range']) { return new Error(self::WS_ERR_INVALID_PARAM, $name . ' must only contain' . $msg . ' floats'); } } @@ -496,8 +486,7 @@ public static function checkType(&$param, $type, $name) return new Error(self::WS_ERR_INVALID_PARAM, $name . ' must be an' . $msg . ' integer'); } } elseif (self::hasFlag($type, self::WS_TYPE_FLOAT)) { - if (($param = filter_var($param, FILTER_VALIDATE_FLOAT)) === false - or (isset($opts['options']['min_range']) and $param < $opts['options']['min_range'])) { + if ($param = filter_var($param, FILTER_VALIDATE_FLOAT) === false || isset($opts['options']['min_range']) && $param < $opts['options']['min_range']) { return new Error(self::WS_ERR_INVALID_PARAM, $name . ' must be a' . $msg . ' float'); } } @@ -548,11 +537,11 @@ public function invoke(string $methodName, array $params) self::makeArrayParam($params[$name]); } } - } elseif ($params[$name] === '' and !self::hasFlag($flags, self::WS_PARAM_OPTIONAL)) { // parameter provided but empty + } elseif ($params[$name] === '' && !self::hasFlag($flags, self::WS_PARAM_OPTIONAL)) { // parameter provided but empty $missing_params[] = $name; } else { // parameter provided - do some basic checks $the_param = $params[$name]; - if (is_array($the_param) and !self::hasFlag($flags, self::WS_PARAM_ACCEPT_ARRAY)) { + if (is_array($the_param) && !self::hasFlag($flags, self::WS_PARAM_ACCEPT_ARRAY)) { return new Error(self::WS_ERR_INVALID_PARAM, $name . ' must be scalar'); } @@ -560,13 +549,11 @@ public function invoke(string $methodName, array $params) self::makeArrayParam($the_param); } - if ($options['type'] > 0) { - if (($ret = self::checkType($the_param, $options['type'], $name)) !== null) { - return $ret; - } + if ($options['type'] > 0 && $ret = self::checkType($the_param, $options['type'], $name) !== null) { + return $ret; } - if (isset($options['maxValue']) and $the_param > $options['maxValue']) { + if (isset($options['maxValue']) && $the_param > $options['maxValue']) { $the_param = $options['maxValue']; } @@ -574,7 +561,7 @@ public function invoke(string $methodName, array $params) } } - if (count($missing_params)) { + if ($missing_params !== []) { return new Error(self::WS_ERR_MISSING_PARAM, 'Missing parameters: ' . implode(',', $missing_params)); } diff --git a/src/Repository/AlbumRepository.php b/src/Repository/AlbumRepository.php index fc84b8d2a..de0aa4b1b 100644 --- a/src/Repository/AlbumRepository.php +++ b/src/Repository/AlbumRepository.php @@ -181,7 +181,7 @@ public function findAlbumsForImage(int $image_id) /** * @param int[] $forbidden_albums */ - public function getQueryBuilderForFindAllowedAlbums(array $forbidden_albums = [], QueryBuilder $qb = null): QueryBuilder + public function getQueryBuilderForFindAllowedAlbums(array $forbidden_albums = [], ? QueryBuilder $qb = null): QueryBuilder { $method = 'andWhere'; @@ -190,7 +190,7 @@ public function getQueryBuilderForFindAllowedAlbums(array $forbidden_albums = [] $method = 'where'; } - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->$method($qb->expr()->notIn('a.id', $forbidden_albums)); } @@ -239,7 +239,7 @@ public function findUnauthorized(array $album_ids = []) $qb->where('a.status = :status'); $qb->setParameter('status', Album::STATUS_PRIVATE); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->andWhere($qb->expr()->notIn('a.id', $album_ids)); } @@ -321,7 +321,7 @@ public function findPrivateWithUserAccessAndNotExclude(int $user_id, array $excl $qb->andWhere('a.status = :status'); $qb->setParameter('status', Album::STATUS_PRIVATE); - if (count($exclude_album_ids) > 0) { + if ($exclude_album_ids !== []) { $qb->andWhere($qb->expr()->notIn('a.id', $exclude_album_ids)); } @@ -582,7 +582,7 @@ public function findWrongRepresentant(array $album_ids = []) $qb->leftJoin('a.imageAlbums', 'ia'); $qb->leftJoin('ia.image', 'i', Join::WITH, 'a.representative_picture_id = i.id'); $qb->where($qb->expr()->isNotNull('a.representative_picture_id')); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->andWhere($qb->expr()->in('a.id', $album_ids)); } $qb->andWhere($qb->expr()->isNotNull('i.id')); @@ -606,7 +606,7 @@ public function findNeedeedRandomRepresentant(array $album_ids = []) $qb->select('DISTINCT(a.id)'); $qb->leftJoin('a.imageAlbums', 'ia'); $qb->where($qb->expr()->isNull('a.representative_picture_id')); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->andWhere($qb->expr()->in('a.id', $album_ids)); } $qb->andWhere($qb->expr()->isNotNull('ia.image')); diff --git a/src/Repository/CaddieRepository.php b/src/Repository/CaddieRepository.php index 5100ff494..a1140fbdb 100644 --- a/src/Repository/CaddieRepository.php +++ b/src/Repository/CaddieRepository.php @@ -44,7 +44,7 @@ public function emptyCaddies(int $user_id): void /** * @param int[] $image_ids */ - public function deleteElements(array $image_ids, int $user_id = null): void + public function deleteElements(array $image_ids, ?int $user_id = null): void { $qb = $this->createQueryBuilder('c'); $qb->delete(); diff --git a/src/Repository/CommentRepository.php b/src/Repository/CommentRepository.php index d91bc5576..2940e4d56 100644 --- a/src/Repository/CommentRepository.php +++ b/src/Repository/CommentRepository.php @@ -267,7 +267,7 @@ public function getCommentsOnImage(int $image_id, string $order, int $limit, int * * @return Comment[]|int */ - public function getNewComments(array $forbidden_albums = [], DateTimeInterface $start = null, DateTimeInterface $end = null, bool $count_only = false): array|int + public function getNewComments(array $forbidden_albums = [], ?DateTimeInterface $start = null, ?DateTimeInterface $end = null, bool $count_only = false): array|int { $qb = $this->createQueryBuilder('c'); @@ -278,7 +278,7 @@ public function getNewComments(array $forbidden_albums = [], DateTimeInterface $ $qb->leftJoin('c.image', 'i'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums)) { + if ($forbidden_albums !== []) { $qb->where($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -302,7 +302,7 @@ public function getNewComments(array $forbidden_albums = [], DateTimeInterface $ /** * @return Comment[]|int */ - public function getUnvalidatedComments(bool $count_only, DateTimeInterface $start = null, DateTimeInterface $end = null): array|int + public function getUnvalidatedComments(bool $count_only, ?DateTimeInterface $start = null, ?DateTimeInterface $end = null): array|int { $qb = $this->createQueryBuilder('c'); @@ -340,7 +340,7 @@ public function countAvailableComments(array $forbidden_albums = [], bool $isAdm $qb->leftJoin('c.image', 'i'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->where($qb->expr()->notIn('ia.album', $forbidden_albums)); } diff --git a/src/Repository/FavoriteRepository.php b/src/Repository/FavoriteRepository.php index 899e8f17f..685c55ade 100644 --- a/src/Repository/FavoriteRepository.php +++ b/src/Repository/FavoriteRepository.php @@ -42,7 +42,7 @@ public function findUserFavorites(int $user_id, array $forbidden_albums = []) $qb->where('f.user = :user_id'); $qb->setParameter('user_id', $user_id); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->leftJoin('f.image', 'i'); $qb->leftJoin('i.imageAlbums', 'ia'); $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); diff --git a/src/Repository/GroupRepository.php b/src/Repository/GroupRepository.php index decc960d9..0f0fb58be 100644 --- a/src/Repository/GroupRepository.php +++ b/src/Repository/GroupRepository.php @@ -115,7 +115,7 @@ public function findByNameOrGroupIds(?string $name = null, array $group_ids = [] $qb->setParameter('name', $name); } - if (count($group_ids) > 0) { + if ($group_ids !== []) { $qb->andWhere($qb->expr()->in('g.id', $group_ids)); } @@ -145,7 +145,7 @@ public function findWithAlbumsAccess(array $album_ids = []) $qb = $this->createQueryBuilder('g'); $qb->leftJoin('g.group_access', 'ga'); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->where($qb->expr()->in('ga.cat_id', $album_ids)); } diff --git a/src/Repository/HistoryRepository.php b/src/Repository/HistoryRepository.php index 3c0a58705..b67718518 100644 --- a/src/Repository/HistoryRepository.php +++ b/src/Repository/HistoryRepository.php @@ -11,6 +11,8 @@ namespace App\Repository; +use DateTime; +use App\Entity\User; use App\Entity\History; use App\Form\Model\SearchRulesModel; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; @@ -43,12 +45,12 @@ public function getHistory(SearchRulesModel $rules, array $types, int $limit, in { $qb = $this->createQueryBuilder('h'); - if ($rules->getStart()) { + if ($rules->getStart() instanceof DateTime) { $qb->where('h.date >= :start'); $qb->setParameter('start', $rules->getStart()); } - if ($rules->getEnd()) { + if ($rules->getEnd() instanceof DateTime) { $qb->andWhere('h.date <= :end'); $qb->setParameter('end', $rules->getEnd()); } @@ -65,12 +67,12 @@ public function getHistory(SearchRulesModel $rules, array $types, int $limit, in } } } - if (count($orXExpressions) > 0) { + if ($orXExpressions !== []) { $qb->andWhere($qb->expr()->orX(...$orXExpressions)); } } - if ($rules->getUser()) { + if ($rules->getUser() instanceof User) { $qb->andWhere('h.user = :user'); $qb->setParameter('user', $rules->getUser()); } @@ -80,7 +82,7 @@ public function getHistory(SearchRulesModel $rules, array $types, int $limit, in $qb->setParameter('image_id', $rules->getImageId()); } - if (count($rules->getImageIds()) > 0) { + if ($rules->getImageIds() !== []) { $qb->andWhere($qb->expr()->in('h.image', $rules->getImageIds())); } diff --git a/src/Repository/ImageAlbumRepository.php b/src/Repository/ImageAlbumRepository.php index e9f4b6e95..ad6045b00 100644 --- a/src/Repository/ImageAlbumRepository.php +++ b/src/Repository/ImageAlbumRepository.php @@ -41,11 +41,11 @@ public function countTotalImages(string $access_type, array $forbidden_albums = $qb = $this->createQueryBuilder('ia'); $qb->select('count(distinct(ia.image))'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->where($qb->expr()->notIn('ia.album', $forbidden_albums)); } - if (count($image_ids) > 0) { + if ($image_ids !== []) { if ($access_type === 'NOT IN') { $qb->andWhere($qb->expr()->notIn('ia.image', $image_ids)); } else { @@ -190,18 +190,18 @@ public function updateRankForImage(int $rank, int $image_id, int $album_id): voi */ public function deleteByAlbum(array $ids = [], array $image_ids = []): void { - if (count($ids) === 0 && count($image_ids) === 0) { + if ($ids === [] && $image_ids === []) { return; } $qb = $this->createQueryBuilder('ia'); $qb->delete(); - if (count($ids) > 0) { + if ($ids !== []) { $qb->where($qb->expr()->in('ia.album', $ids)); } - if (count($image_ids) > 0) { + if ($image_ids !== []) { $qb->andWhere($qb->expr()->in('ia.image', $image_ids)); } @@ -216,7 +216,7 @@ public function deleteByImages(array $ids = []): void $qb = $this->createQueryBuilder('ia'); $qb->delete(); - if (count($ids) > 0) { + if ($ids !== []) { $qb->where($qb->expr()->in('ia.image', $ids)); } @@ -243,7 +243,7 @@ public function getRelatedAlbum(int $image_id, array $forbidden_albums = []) $qb->where('ia.image = :image_id'); $qb->setParameter('image_id', $image_id); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } diff --git a/src/Repository/ImageRepository.php b/src/Repository/ImageRepository.php index d49c66bd0..92cb703b0 100644 --- a/src/Repository/ImageRepository.php +++ b/src/Repository/ImageRepository.php @@ -100,7 +100,7 @@ public function findWithNoStorageOrStorageForAlbums(array $album_ids = []) $qb = $this->createQueryBuilder('i'); $qb->where($qb->expr()->isNull('i.storage_category_id')); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->orWhere($qb->expr()->notIn('i.storage_category_id', $album_ids)); } @@ -121,7 +121,7 @@ public function getForbiddenImages(array $forbidden_albums = [], int $level = 0) $qb->where('i.level > :level'); $qb->setParameter('level', $level); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -140,7 +140,7 @@ public function findMostVisited(array $forbidden_albums = [], array $sorts = [], $qb->leftJoin('i.imageAlbums', 'ia'); $qb->where('i.hit > 0'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -169,7 +169,7 @@ public function findRecentImages(DateTimeInterface $recent_date, array $forbidde $qb->where('i.date_available >= :recent_date'); $qb->setParameter('recent_date', $recent_date); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -204,7 +204,7 @@ public function findBestRated(int $limit, array $forbidden_albums = [], array $s $qb->leftJoin('i.imageAlbums', 'ia'); $qb->where($qb->expr()->isNotNull('i.rating_score')); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -227,7 +227,7 @@ public function findRandomImages(int $max, array $forbidden_albums = []) $qb = $this->createQueryBuilder('i'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -268,7 +268,7 @@ public function getRandomImageInAlbum(int $album_id, string $uppercats = '', arr $qb->setParameter('uppercats', $uppercats . ',%'); } - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('a.id', $forbidden_albums)); } $nb_images = $qb->getQuery()->getSingleScalarResult(); @@ -285,7 +285,7 @@ public function getRandomImageInAlbum(int $album_id, string $uppercats = '', arr $qb->setParameter('uppercats', $uppercats . ',%'); } - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('a.id', $forbidden_albums)); } $qb->setFirstResult(random_int(0, $nb_images - 1)); @@ -309,7 +309,7 @@ public function getList(array $ids, array $forbidden_albums = []) $qb->leftJoin('i.imageAlbums', 'ia'); $qb->where($qb->expr()->in('i.id', $ids)); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -321,7 +321,7 @@ public function getList(array $ids, array $forbidden_albums = []) * * @return Image[]|int */ - public function getNewElements(array $forbidden_albums = [], DateTimeInterface $start = null, DateTimeInterface $end = null, bool $count_only = false): array|int + public function getNewElements(array $forbidden_albums = [], ?DateTimeInterface $start = null, ?DateTimeInterface $end = null, bool $count_only = false): array|int { $qb = $this->createQueryBuilder('i'); if ($count_only) { @@ -339,7 +339,7 @@ public function getNewElements(array $forbidden_albums = [], DateTimeInterface $ $qb->setParameter('end', $end); } - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -355,7 +355,7 @@ public function getNewElements(array $forbidden_albums = [], DateTimeInterface $ * * @return Album[]|int */ - public function getUpdatedAlbums(array $forbidden_albums = [], DateTimeInterface $start = null, DateTimeInterface $end = null, bool $count_only = false): array|int + public function getUpdatedAlbums(array $forbidden_albums = [], ?DateTimeInterface $start = null, ?DateTimeInterface $end = null, bool $count_only = false): array|int { return $this->getNewElements($forbidden_albums, $start, $end, $count_only); } @@ -365,7 +365,7 @@ public function getUpdatedAlbums(array $forbidden_albums = [], DateTimeInterface * * @return array */ - public function getRecentImages(int $limit, DateTimeInterface $date_available = null, array $forbidden_albums = []) + public function getRecentImages(int $limit, ?DateTimeInterface $date_available = null, array $forbidden_albums = []) { $qb = $this->createQueryBuilder('i'); $qb->select('DISTINCT(a.uppercats) AS upp, COUNT(i.id) AS img_count'); @@ -374,7 +374,7 @@ public function getRecentImages(int $limit, DateTimeInterface $date_available = $qb->where('i.date_available = :date_avaiable'); $qb->setParameter('date_avaiable', $date_available); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -401,7 +401,7 @@ public function getRecentPostedImages(int $limit, array $forbidden_albums = []) $qb->select('i.date_available, COUNT(DISTINCT(i.id)) AS nb_elements'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -429,7 +429,7 @@ public function searchDistinctId(array $forbidden_albums = [], array $order_by = // $qb->select('DISTINCT(i.id) AS id'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -457,7 +457,7 @@ public function searchDistinctIdInAlbum(int $album_id, array $forbidden_albums = $qb->where('ia.album = :album_id'); $qb->setParameter('album_id', $album_id); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -493,12 +493,12 @@ public function countImagesByYear(string $date_type = 'posted', array $forbidden $andXExpression = []; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $andXExpression[] = $qb->expr()->notIn('ia.album', ':ids'); $qb->setParameter('ids', $forbidden_albums); } - if (count($andXExpression) > 0) { + if ($andXExpression !== []) { $qb->having($qb->expr()->andX(...$andXExpression)); } @@ -515,7 +515,7 @@ public function countImagesByYear(string $date_type = 'posted', array $forbidden */ public function findOneImagePerYear(array $years = [], string $date_type = 'posted', array $forbidden_albums = []) { - if (count($years) === 0) { + if ($years === []) { return []; } @@ -523,14 +523,14 @@ public function findOneImagePerYear(array $years = [], string $date_type = 'post $fmt .= ' LEFT JOIN phyxo_image_category ic ON i.id = ic.image_id'; $fmt .= ' WHERE'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $fmt .= ' ic.category_id NOT IN(%s) AND'; } $fmt .= ' EXTRACT(YEAR FROM %s) = ?'; $fmt .= ' LIMIT 1)'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $sql_select = sprintf($fmt, implode(', ', $forbidden_albums), $this->getFieldFromDateType($date_type)); } else { /** @phpstan-ignore-next-line */ @@ -566,7 +566,7 @@ public function countImagesByMonth(int $year, string $date_type = 'posted', arra $qb->groupBy('month'); $qb->orderBy('month', 'ASC'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -581,7 +581,7 @@ public function countImagesByMonth(int $year, string $date_type = 'posted', arra */ public function findOneImagePerMonth(int $year, array $months = [], string $date_type = 'posted', array $forbidden_albums = []) { - if (count($months) === 0) { + if ($months === []) { return []; } @@ -589,7 +589,7 @@ public function findOneImagePerMonth(int $year, array $months = [], string $date $fmt .= ' LEFT JOIN phyxo_image_category ic ON i.id = ic.image_id'; $fmt .= ' WHERE'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $fmt .= ' ic.category_id NOT IN(%s) AND'; } @@ -597,7 +597,7 @@ public function findOneImagePerMonth(int $year, array $months = [], string $date $fmt .= ' AND EXTRACT(YEAR FROM %s) = :year'; $fmt .= ' LIMIT 1)'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $sql_select = sprintf($fmt, implode(', ', $forbidden_albums), $this->getFieldFromDateType($date_type), $this->getFieldFromDateType($date_type)); } else { /** @phpstan-ignore-next-line */ @@ -636,7 +636,7 @@ public function countImagesByDay(int $year, int $month, string $date_type = 'pos $qb->setParameter('month', $month); $qb->orderBy('day', 'ASC'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -651,7 +651,7 @@ public function countImagesByDay(int $year, int $month, string $date_type = 'pos */ public function findOneImagePerDay(int $year, int $month, array $days = [], string $date_type = 'posted', array $forbidden_albums = []) { - if (count($days) === 0) { + if ($days === []) { return []; } @@ -659,7 +659,7 @@ public function findOneImagePerDay(int $year, int $month, array $days = [], stri $fmt .= ' LEFT JOIN phyxo_image_category ic ON i.id = ic.image_id'; $fmt .= ' WHERE'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $fmt .= ' ic.category_id NOT IN(%s) AND'; } @@ -668,7 +668,7 @@ public function findOneImagePerDay(int $year, int $month, array $days = [], stri $fmt .= ' AND EXTRACT(YEAR FROM %s) = :year'; $fmt .= ' LIMIT 1)'; - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $sql_select = sprintf( $fmt, implode(', ', $forbidden_albums), @@ -708,7 +708,7 @@ public function findImagesPerDate(DateTimeInterface $date, string $date_type = ' $qb->leftJoin('i.imageAlbums', 'ia'); $qb->where('DATE(i.' . $this->getFieldFromDateType($date_type) . ') = :date'); $qb->setParameter('date', $date); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -991,7 +991,7 @@ public function findGroupByAuthor(array $forbidden_albums = []) $qb = $this->createQueryBuilder('i'); $qb->leftJoin('i.imageAlbums', 'ia'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->where($qb->expr()->notIn('ia.album', $forbidden_albums)); } $qb->andWhere($qb->expr()->isNotNull('i.author')); @@ -1028,7 +1028,7 @@ public function qSearchImages(string $words, array $forbidden_albums = []) $search_value = '%' . str_replace(' ', '%', trim(strtolower($words))) . '%'; $qb = $this->createQueryBuilder('i'); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->leftJoin('i.imageAlbums', 'ia'); $qb->where($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -1054,7 +1054,7 @@ public function searchImages(array $rules, array $forbidden_albums = []) $whereMethod = $rules['mode'] == 'AND' ? 'andWhere' : 'orWhere'; $qb = $this->createQueryBuilder('i'); - if (count($forbidden_albums) > 0 || isset($rules['fields']['cat'])) { + if ($forbidden_albums !== [] || isset($rules['fields']['cat'])) { $qb->leftJoin('i.imageAlbums', 'ia'); } @@ -1072,7 +1072,7 @@ public function searchImages(array $rules, array $forbidden_albums = []) } } } - if (count($clauses) > 0) { + if ($clauses !== []) { $qb->$whereMethod(...$clauses); } @@ -1099,7 +1099,7 @@ public function searchImages(array $rules, array $forbidden_albums = []) $qb->$whereMethod(...$clauses); } - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -1151,7 +1151,7 @@ public function isAuthorizedToUser(int $image_id, array $forbidden_albums = []): $qb->where('i.id = :image_id'); $qb->setParameter('image_id', $image_id); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } @@ -1166,7 +1166,7 @@ public function isAuthorizedToUser(int $image_id, array $forbidden_albums = []): */ public function getImageIdsForTags(array $forbidden_albums = [], array $tag_ids = [], string $mode = 'AND') { - if (empty($tag_ids)) { + if ($tag_ids === []) { return []; } @@ -1174,7 +1174,7 @@ public function getImageIdsForTags(array $forbidden_albums = [], array $tag_ids $qb->leftJoin('i.imageTags', 'it'); $qb->where($qb->expr()->in('it.tag', $tag_ids)); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->leftJoin('i.imageAlbums', 'ia'); $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); } diff --git a/src/Repository/ImageTagRepository.php b/src/Repository/ImageTagRepository.php index 94dd95dc1..722163135 100644 --- a/src/Repository/ImageTagRepository.php +++ b/src/Repository/ImageTagRepository.php @@ -82,7 +82,7 @@ public function getAvailableTags(int $user_id, array $forbidden_albums = [], boo $this->addValidatedCondition($qb, $user_id, $show_pending_added_tags, $show_pending_deleted_tags); - if (count($forbidden_albums) > 0) { + if ($forbidden_albums !== []) { $qb->leftJoin('it.image', 'i'); $qb->leftJoin('i.imageAlbums', 'ia'); $qb->andWhere($qb->expr()->notIn('ia.album', $forbidden_albums)); diff --git a/src/Repository/RateRepository.php b/src/Repository/RateRepository.php index 16d548983..be30bb1d8 100644 --- a/src/Repository/RateRepository.php +++ b/src/Repository/RateRepository.php @@ -46,7 +46,7 @@ public function calculateRateSummary(int $image_id) return $qb->getQuery()->getOneOrNullResult(AbstractQuery::HYDRATE_SCALAR); } - public function countImagesRatedForUser(int $user_id, string $operator = null) : int + public function countImagesRatedForUser(int $user_id, ?string $operator = null) : int { $qb = $this->createQueryBuilder('r'); $qb->select('COUNT(DISTINCT(r.image))'); @@ -59,7 +59,7 @@ public function countImagesRatedForUser(int $user_id, string $operator = null) : return $qb->getQuery()->getSingleScalarResult(); } - public function getRatePerImage(int $user_id, string $order, int $limit, string $operator = null, int $offset = 0) + public function getRatePerImage(int $user_id, string $order, int $limit, ?string $operator = null, int $offset = 0) { $qb = $this->createQueryBuilder('r'); $qb->leftJoin('r.image', 'i'); diff --git a/src/Repository/TagRepository.php b/src/Repository/TagRepository.php index 58f25f727..a4c531f96 100644 --- a/src/Repository/TagRepository.php +++ b/src/Repository/TagRepository.php @@ -42,7 +42,7 @@ public function addOrUpdateTag(Tag $tag): int public function searchAll(string $q = '') { $qb = $this->createQueryBuilder('t'); - if (!empty($q)) { + if ($q !== '' && $q !== '0') { $qb->where($qb->expr()->like("lower('t.name')", ':q')); $qb->setParameter('q', '%' . strtolower($q) . '%'); } @@ -72,15 +72,15 @@ public function findByIdsOrNamesOrUrlNames(array $ids = [], array $names = [], a { $qb = $this->createQueryBuilder('t'); - if (count($ids) > 0) { + if ($ids !== []) { $qb->where($qb->expr()->in('t.id', $ids)); } - if (count($names) > 0) { + if ($names !== []) { $qb->orWhere($qb->expr()->in('t.name', $names)); } - if (count($url_names) > 0) { + if ($url_names !== []) { $qb->orWhere($qb->expr()->in('t.url_name', $url_names)); } @@ -99,13 +99,13 @@ public function getCommonTags(int $user_id, array $items, int $max_tags, array $ $qb->leftJoin('t.imageTags', 'it'); $qb->addSelect('COUNT(1) AS counter'); - if (count($items) > 0) { + if ($items !== []) { $qb->where($qb->expr()->in('it.image', $items)); } $this->addValidatedCondition($qb, $user_id); - if (count($excluded_tag_ids) > 0) { + if ($excluded_tag_ids !== []) { $qb->andWhere($qb->expr()->notIn('t.id', $excluded_tag_ids)); } diff --git a/src/Repository/UserCacheAlbumRepository.php b/src/Repository/UserCacheAlbumRepository.php index e4ad98263..a3c5a1eac 100644 --- a/src/Repository/UserCacheAlbumRepository.php +++ b/src/Repository/UserCacheAlbumRepository.php @@ -57,7 +57,7 @@ public function deleteForAlbums(array $album_ids): void $qb = $this->createQueryBuilder('ucc'); $qb->delete(); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->where($qb->expr()->in('ucc.album', $album_ids)); } diff --git a/src/Repository/UserInfosRepository.php b/src/Repository/UserInfosRepository.php index f1984ddcb..546e8df75 100644 --- a/src/Repository/UserInfosRepository.php +++ b/src/Repository/UserInfosRepository.php @@ -58,7 +58,7 @@ public function updateFieldsForUsers(array $fields, array $user_ids = []): void $qb->set('u.' . $field, ':' . $field); $qb->setParameter($field, $value); } - if (count($user_ids) > 0) { + if ($user_ids !== []) { $qb->where($qb->expr()->in('u.user', $user_ids)); } @@ -83,7 +83,7 @@ public function updateLanguageForLanguages(string $language, array $languages): /** * @return UserInfos[] */ - public function getNewUsers(DateTimeInterface $start = null, DateTimeInterface $end = null) + public function getNewUsers(?DateTimeInterface $start = null, ?DateTimeInterface $end = null) { $qb = $this->createQueryBuilder('u'); $this->addBetweenDateCondition($qb, $start, $end); @@ -91,7 +91,7 @@ public function getNewUsers(DateTimeInterface $start = null, DateTimeInterface $ return $qb->getQuery()->getResult(); } - public function countNewUsers(DateTimeInterface $start = null, DateTimeInterface $end = null): int + public function countNewUsers(?DateTimeInterface $start = null, ?DateTimeInterface $end = null): int { $qb = $this->createQueryBuilder('u'); $qb->select('count(1)'); @@ -100,7 +100,7 @@ public function countNewUsers(DateTimeInterface $start = null, DateTimeInterface return $qb->getQuery()->getSingleScalarResult(); } - private function addBetweenDateCondition(QueryBuilder $qb, DateTimeInterface $start = null, DateTimeInterface $end = null): QueryBuilder + private function addBetweenDateCondition(QueryBuilder $qb, ?DateTimeInterface $start = null, ?DateTimeInterface $end = null): QueryBuilder { if (!is_null($start)) { $qb->andWhere('u.registration_date > :start'); diff --git a/src/Repository/UserMailNotificationRepository.php b/src/Repository/UserMailNotificationRepository.php index de7e591e4..09572e196 100644 --- a/src/Repository/UserMailNotificationRepository.php +++ b/src/Repository/UserMailNotificationRepository.php @@ -53,7 +53,7 @@ public function findInfosForUsers(bool $send, ?bool $enabled_filter_value, array $qb->setParameter('enabled', $enabled_filter_value); } - if (count($check_keys) > 0) { + if ($check_keys !== []) { $qb->andWhere($qb->expr()->in('n.check_key', $check_keys)); } diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 29ecc5121..2a614bd46 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -127,7 +127,7 @@ public function findWithAlbumsAccess(array $album_ids = []) $qb = $this->createQueryBuilder('u'); $qb->leftJoin('u.user_access', 'ua'); - if (count($album_ids) > 0) { + if ($album_ids !== []) { $qb->where($qb->expr()->in('ua.cat_id', $album_ids)); } diff --git a/src/Security/AppUserService.php b/src/Security/AppUserService.php index c5cda6613..c70bbd579 100644 --- a/src/Security/AppUserService.php +++ b/src/Security/AppUserService.php @@ -95,11 +95,6 @@ public function canManageComment(string $action, int $comment_author_id): bool if (($action === 'edit' && $this->conf['user_can_edit_comment']) && ($comment_author_id === $this->getUser()->getId())) { return true; } - - if (($action === 'delete' && $this->conf['user_can_delete_comment']) && ($comment_author_id == $this->getUser()->getId())) { - return true; - } - - return false; + return $action === 'delete' && $this->conf['user_can_delete_comment'] && $comment_author_id == $this->getUser()->getId(); } } diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index ab48c53dc..8a2a30acf 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -38,9 +38,9 @@ public function supports(Request $request): bool return $request->isMethod('POST') && $request->attributes->get('_route') === 'login'; } - public function start(Request $request, AuthenticationException $authException = null): Response + public function start(Request $request, ?AuthenticationException $authException = null): Response { - if ($authException !== null) { + if ($authException instanceof AuthenticationException) { $request->getSession()->set('_redirect', true); } diff --git a/src/Security/TagVoter.php b/src/Security/TagVoter.php index ef7d3fb42..1a3608468 100644 --- a/src/Security/TagVoter.php +++ b/src/Security/TagVoter.php @@ -37,12 +37,7 @@ protected function supports(string $attribute, mixed $subject): bool if (!in_array($attribute, [self::ADD, self::DELETE])) { return false; } - - if (!$subject instanceof Image) { - return false; - } - - return true; + return $subject instanceof Image; } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool diff --git a/src/Security/UserProvider.php b/src/Security/UserProvider.php index 14233a689..e03f5d4e0 100644 --- a/src/Security/UserProvider.php +++ b/src/Security/UserProvider.php @@ -52,7 +52,7 @@ public function loadUserByIdentifier(string $identifier): User public function loadByActivationKey(string $key): User { - if (($user = $this->fetchUserByActivationKey($key)) === null) { + if (!($user = $this->fetchUserByActivationKey($key)) instanceof User) { throw new TokenNotFoundException(sprintf('Activation key "%s" does not exist.', $key)); } @@ -137,7 +137,7 @@ private function getUserCacheInfos(User $user): UserCache $this->albumMapper->removeComputedAlbum($user_cache_albums, $album_infos); } } - if (count($forbidden_ids) > 0) { + if ($forbidden_ids !== []) { $forbidden_albums = array_merge($forbidden_albums, $forbidden_ids); } } diff --git a/src/Services/DerivativeService.php b/src/Services/DerivativeService.php index c0b6dceed..a469dfc9b 100644 --- a/src/Services/DerivativeService.php +++ b/src/Services/DerivativeService.php @@ -28,7 +28,8 @@ public function __construct(private readonly string $mediaCacheDir, private read */ public function clearCache(array $types, array $all_types) { - for ($i = 0; $i < count($types); $i++) { + $counter = count($types); + for ($i = 0; $i < $counter; $i++) { $type = $types[$i]; if ($type === ImageStandardParams::IMG_CUSTOM) { $pattern = DerivativeParams::derivative_to_url($type) . '[a-zA-Z0-9]+'; @@ -77,11 +78,7 @@ public function deleteForElement(array $infos, $type = 'all') } $dot = strrpos($relative_path, '.'); - if ($type == 'all') { - $pattern = '-.*'; - } else { - $pattern = '-' . DerivativeParams::derivative_to_url($type) . '.*'; - } + $pattern = $type == 'all' ? '-.*' : '-' . DerivativeParams::derivative_to_url($type) . '.*'; $pattern = '#' . substr_replace($relative_path, $pattern, $dot, 0) . '#'; $finder = new Finder(); diff --git a/src/Twig/DerivativeExtension.php b/src/Twig/DerivativeExtension.php index 1d54b0178..949a69727 100644 --- a/src/Twig/DerivativeExtension.php +++ b/src/Twig/DerivativeExtension.php @@ -67,7 +67,7 @@ public function defineDerivative(array $params): DerivativeParams $crop = (int) round($params['crop'] / 100, 2); } - if ($crop) { + if ($crop !== 0) { $minw = empty($params['min_width']) ? $w : intval($params['min_width']); if ($minw > $w) { throw new Exception('define_derivative invalid min_width'); diff --git a/src/Twig/PhyxoAssetExtension.php b/src/Twig/PhyxoAssetExtension.php index aad6e4b31..e876d568e 100644 --- a/src/Twig/PhyxoAssetExtension.php +++ b/src/Twig/PhyxoAssetExtension.php @@ -30,7 +30,7 @@ public function getFunctions(): array public function getAssetPath(string $path, string $manifestRelativeFile = ''): string { - if (empty($manifestRelativeFile)) { + if ($manifestRelativeFile === '' || $manifestRelativeFile === '0') { return $path; } diff --git a/src/Utils/RuntimeTranslator.php b/src/Utils/RuntimeTranslator.php index 2b06f9e8d..42ad9ed3b 100644 --- a/src/Utils/RuntimeTranslator.php +++ b/src/Utils/RuntimeTranslator.php @@ -41,7 +41,7 @@ public function __call(string $method, mixed $args): mixed return $this->translator->{$method}(...$args); } - public function getCatalogue($locale = null): MessageCatalogueInterface + public function getCatalogue(?string $locale = null): MessageCatalogueInterface { return $this->translator->getCatalogue($locale); } @@ -67,7 +67,7 @@ public function getLocale(): string /** * @param array $parameters */ - public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string { if ($locale === null) { $locale = $this->getLocale(); @@ -85,7 +85,7 @@ public function trans(string $id, array $parameters = [], string $domain = null, return $this->formatter->format($runtimeCatalogue->get($id, $domain), $locale, $parameters); } - public function addRuntimeResource(string $format, string $resource, string $locale, string $domain = null): void + public function addRuntimeResource(string $format, string $resource, string $locale, ?string $domain = null): void { if ($format !== 'php') { return; diff --git a/symfony.lock b/symfony.lock index 66a34d5e8..d451c5b1a 100644 --- a/symfony.lock +++ b/symfony.lock @@ -366,15 +366,16 @@ "version": "v5.4.3" }, "symfony/flex": { - "version": "1.19", + "version": "2.4", "recipe": { "repo": "github.com/symfony/recipes", "branch": "main", - "version": "1.0", - "ref": "146251ae39e06a95be0fe3d13c807bcf3938b172" + "version": "2.4", + "ref": "52e9754527a15e2b79d9a610f98185a1fe46622a" }, "files": [ - ".env" + ".env", + ".env.dev" ] }, "symfony/form": { diff --git a/tests/Behat/ApiContext.php b/tests/Behat/ApiContext.php index 1d37b86f9..4614be5a7 100644 --- a/tests/Behat/ApiContext.php +++ b/tests/Behat/ApiContext.php @@ -68,11 +68,11 @@ public function iAmAuthenticatedForApiAs(string $username, string $password) public function iSendARequestWithValues(string $http_method, string $method, ?TableNode $values = null) { $requestOptions = []; - if ($http_method == 'GET') { + if ($http_method === 'GET') { $requestOptions['query']['method'] = $method; - } elseif ($http_method == 'POST') { + } elseif ($http_method === 'POST') { $requestOptions['form_params'] = []; - if ($values !== null) { + if ($values instanceof TableNode) { foreach ($values->getColumnsHash() as $columHash) { $requestOptions['form_params'] = $columHash; } @@ -156,7 +156,7 @@ private function getProperty($data, $property) $parts = explode('/', (string) $property); $n = 0; while ($n < count($parts)) { - if (is_null($data[$parts[$n]]) && ($n + 1) == count($parts)) { + if (is_null($data[$parts[$n]]) && $n + 1 === count($parts)) { $data = ''; } else { if (!isset($data[$parts[$n]])) { diff --git a/tests/Behat/BaseContext.php b/tests/Behat/BaseContext.php index e9606f030..2a8614f39 100644 --- a/tests/Behat/BaseContext.php +++ b/tests/Behat/BaseContext.php @@ -62,7 +62,7 @@ public function spins(Closure $closure, int $tries = 3): void return; } catch (Exception $e) { - if ($i == $tries) { + if ($i === $tries) { throw $e; } } @@ -73,7 +73,7 @@ public function spins(Closure $closure, int $tries = 3): void public function findByDataTestid(string $data_id, NodeElement $parent = null): NodeElement { - if ($parent === null) { + if (!$parent instanceof NodeElement) { $parent = $this->getSession()->getPage(); } $element = $parent->find('css', sprintf('*[data-testid="%s"]', $data_id)); diff --git a/tests/Behat/DBContext.php b/tests/Behat/DBContext.php index 84453f67d..761d16364 100644 --- a/tests/Behat/DBContext.php +++ b/tests/Behat/DBContext.php @@ -72,7 +72,7 @@ public function givenUsers(TableNode $table): void $user = new User(); $user->setUsername($userRow['username']); $user->setPassword($this->getContainer()->get('security.password_hasher')->hashPassword($user, $userRow['password'])); - $user->addRole(User::getRoleFromStatus(!empty($userRow['status']) ? $userRow['status'] : User::STATUS_NORMAL)); + $user->addRole(User::getRoleFromStatus(empty($userRow['status']) ? User::STATUS_NORMAL : $userRow['status'])); if (!empty($userRow['mail_address'])) { $user->setMailAddress($userRow['mail_address']); } @@ -385,11 +385,7 @@ protected function addTagsToImage(array $tags, int $image_id, int $user_id = nul } $image = $this->imageMapper->getRepository()->find($image_id); - if (!is_null($user_id)) { - $user = $this->userRepository->find($user_id); - } else { - $user = $this->userMapper->getDefaultUser(); - } + $user = is_null($user_id) ? $this->userMapper->getDefaultUser() : $this->userRepository->find($user_id); $this->tagMapper->toBeValidatedTags($image, $tag_ids, $user, ImageTag::STATUS_TO_ADD, $validated); } @@ -411,11 +407,7 @@ protected function removeTagsFromImage(array $tags, int $image_id, int $user_id $conf = $this->conf; $image = $this->imageMapper->getRepository()->find($image_id); - if (!is_null($user_id)) { - $user = $this->userRepository->find($user_id); - } else { - $user = $this->userMapper->getDefaultUser(); - } + $user = is_null($user_id) ? $this->userMapper->getDefaultUser() : $this->userRepository->find($user_id); // if publish_tags_immediately (or delete_tags_immediately) is not set we consider its value is true if (isset($conf['publish_tags_immediately']) && $conf['publish_tags_immediately'] === false) { diff --git a/tests/Behat/FeatureContext.php b/tests/Behat/FeatureContext.php index 1f29dcfe7..2be3aeffe 100644 --- a/tests/Behat/FeatureContext.php +++ b/tests/Behat/FeatureContext.php @@ -165,11 +165,7 @@ public function iShouldNotSeeTag(string $tag_name): void */ public function iShouldSeeLink(string $link_label, string $parent = ''): void { - if (!empty($parent)) { - $parentNode = $this->getSession()->getPage()->find('css', $parent); - } else { - $parentNode = $this->getSession()->getPage(); - } + $parentNode = $parent === '' || $parent === '0' ? $this->getSession()->getPage() : $this->getSession()->getPage()->find('css', $parent); $link = $parentNode->findLink($link_label); if ($link === null) {