From dd1f806c4e01b5bcf1f58e0b7c29cfc6e428f647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 1 Feb 2020 17:00:03 +0100 Subject: [PATCH] Fixed some issues detected by PHPstan. --- composer.json | 4 + composer.lock | 219 +++++++++++++++++- phpstan.neon | 12 + src/Command/CleanAttachmentsCommand.php | 6 +- src/Command/ConvertBBCodeCommand.php | 4 +- src/Command/SetPasswordCommand.php | 9 +- src/Command/ShowEventLogCommand.php | 8 +- src/Command/UpdateExchangeRatesCommand.php | 5 +- .../AdminPages/ManufacturerController.php | 2 +- .../AdminPages/StorelocationController.php | 2 +- src/Controller/UserController.php | 4 +- .../Adapter/FetchJoinORMAdapter.php | 2 +- src/DataTables/Adapter/ORMAdapter.php | 1 + .../AttachmentContainingDBElement.php | 2 +- .../LogSystem/DatabaseUpdatedLogEntry.php | 4 +- src/Entity/Parts/PartLot.php | 2 +- src/Entity/Parts/PartTraits/OrderTrait.php | 6 +- src/Entity/PriceInformations/Orderdetail.php | 2 +- src/Form/Type/CurrencyEntityType.php | 4 + .../ElementPermissionListener.php | 3 +- src/Security/Voter/AttachmentVoter.php | 7 +- src/Security/Voter/ExtendedVoter.php | 5 +- src/Security/Voter/GroupVoter.php | 5 +- src/Security/Voter/PermissionVoter.php | 4 +- src/Security/Voter/StructureVoter.php | 6 +- src/Security/Voter/UserVoter.php | 5 +- src/Services/ElementTypeNameGenerator.php | 2 +- src/Services/EntityURLGenerator.php | 6 +- src/Services/PermissionResolver.php | 2 +- symfony.lock | 12 + 30 files changed, 310 insertions(+), 45 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index dcc09497..c11e5071 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,10 @@ "require-dev": { "dama/doctrine-test-bundle": "^6.0", "doctrine/doctrine-fixtures-bundle": "^3.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.8", + "phpstan/phpstan-doctrine": "^0.12.9", + "phpstan/phpstan-symfony": "^0.12.4", "roave/security-advisories": "dev-master", "symfony/debug-pack": "*", "symfony/maker-bundle": "^1.13", diff --git a/composer.lock b/composer.lock index 73489ad2..068b07a5 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": "617502331106c4684d08a9d8937ab286", + "content-hash": "ac7d81adf72ec1f7b8e9c51876584a5f", "packages": [ { "name": "beberlei/assert", @@ -9967,6 +9967,50 @@ ], "time": "2018-02-15T16:58:55+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "295656793c53b5eb73a38486032ad1bd650264bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/295656793c53b5eb73a38486032ad1bd650264bc", + "reference": "295656793c53b5eb73a38486032ad1bd650264bc", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1", + "php": "^7.1", + "phpstan/phpstan": ">=0.11.6" + }, + "require-dev": { + "composer/composer": "^1.8", + "consistence/coding-standard": "^3.8", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "jakub-onderka/php-parallel-lint": "^1.0", + "phing/phing": "^2.16", + "phpstan/phpstan-strict-rules": "^0.11", + "slevomat/coding-standard": "^5.0.4" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "time": "2019-10-18T17:09:48+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "0.4.2", @@ -10015,6 +10059,179 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "time": "2019-12-13T12:03:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.8", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "62a552602b7586d82826231f2fd4cbfe39fe0b1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/62a552602b7586d82826231f2fd4cbfe39fe0b1d", + "reference": "62a552602b7586d82826231f2fd4cbfe39fe0b1d", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "time": "2020-01-26T23:36:48+00:00" + }, + { + "name": "phpstan/phpstan-doctrine", + "version": "0.12.9", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-doctrine.git", + "reference": "af14feb2ed259f9eb16d3107e63d85ed516e30af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/af14feb2ed259f9eb16d3107e63d85ed516e30af", + "reference": "af14feb2ed259f9eb16d3107e63d85ed516e30af", + "shasum": "" + }, + "require": { + "php": "~7.1", + "phpstan/phpstan": "^0.12.3" + }, + "conflict": { + "doctrine/collections": "<1.0", + "doctrine/common": "<2.7", + "doctrine/mongodb-odm": "<1.2", + "doctrine/orm": "<2.5" + }, + "require-dev": { + "consistence/coding-standard": "^3.0.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "doctrine/collections": "^1.0", + "doctrine/common": "^2.7", + "doctrine/mongodb-odm": "^1.2", + "doctrine/orm": "^2.5", + "ergebnis/composer-normalize": "^2.0.2", + "jakub-onderka/php-parallel-lint": "^1.0", + "phing/phing": "^2.16.0", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^7.0", + "ramsey/uuid-doctrine": "^1.5.0", + "slevomat/coding-standard": "^4.5.2" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + }, + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Doctrine extensions for PHPStan", + "time": "2020-01-10T12:31:37+00:00" + }, + { + "name": "phpstan/phpstan-symfony", + "version": "0.12.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-symfony.git", + "reference": "5e4b7ba02f2235271a069deeb88340a210d6c87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/5e4b7ba02f2235271a069deeb88340a210d6c87c", + "reference": "5e4b7ba02f2235271a069deeb88340a210d6c87c", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "php": "^7.1", + "phpstan/phpstan": "^0.12" + }, + "conflict": { + "symfony/framework-bundle": "<3.0" + }, + "require-dev": { + "consistence/coding-standard": "^3.0.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "ergebnis/composer-normalize": "^2.0.2", + "jakub-onderka/php-parallel-lint": "^1.0", + "phing/phing": "^2.16.0", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^7.0", + "slevomat/coding-standard": "^4.5.2", + "squizlabs/php_codesniffer": "^3.3.2", + "symfony/console": "^4.0", + "symfony/framework-bundle": "^4.0", + "symfony/http-foundation": "^4.0", + "symfony/messenger": "^4.2", + "symfony/serializer": "^4.0" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + }, + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lukáš Unger", + "email": "looky.msc@gmail.com", + "homepage": "https://lookyman.net" + } + ], + "description": "Symfony Framework extensions and rules for PHPStan", + "time": "2020-01-22T10:19:41+00:00" + }, { "name": "roave/security-advisories", "version": "dev-master", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..8aea6a8e --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +parameters: + inferPrivatePropertyTypeFromConstructor: true + + symfony: + container_xml_path: '%rootDir%/../../../var/cache/dev/srcApp_KernelDevDebugContainer.xml' + + autoload_directories: + - %rootDir%/../../../src/Migrations + + excludes_analyse: + - src/DataTables/Adapter/* + - src/Configuration/* \ No newline at end of file diff --git a/src/Command/CleanAttachmentsCommand.php b/src/Command/CleanAttachmentsCommand.php index 80f2957c..f099baf2 100644 --- a/src/Command/CleanAttachmentsCommand.php +++ b/src/Command/CleanAttachmentsCommand.php @@ -65,7 +65,7 @@ class CleanAttachmentsCommand extends Command ' These files are not needed and can eventually deleted.'); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -107,7 +107,7 @@ class CleanAttachmentsCommand extends Command if (! $continue) { //We are finished here, when no files should be deleted - return; + return 0; } //Delete the files @@ -119,6 +119,8 @@ class CleanAttachmentsCommand extends Command } else { $io->success('No abandoned files found.'); } + + return 0; } /** diff --git a/src/Command/ConvertBBCodeCommand.php b/src/Command/ConvertBBCodeCommand.php index 6a93f3fa..4bc20246 100644 --- a/src/Command/ConvertBBCodeCommand.php +++ b/src/Command/ConvertBBCodeCommand.php @@ -105,7 +105,7 @@ class ConvertBBCodeCommand extends Command ]; } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $targets = $this->getTargetsLists(); @@ -168,5 +168,7 @@ class ConvertBBCodeCommand extends Command $this->em->flush(); $io->success('Changes saved to DB successfully!'); } + + return 0; } } diff --git a/src/Command/SetPasswordCommand.php b/src/Command/SetPasswordCommand.php index 5e2ecf92..ac895d77 100644 --- a/src/Command/SetPasswordCommand.php +++ b/src/Command/SetPasswordCommand.php @@ -57,19 +57,19 @@ class SetPasswordCommand extends Command ; } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $user_name = $input->getArgument('user'); - /** @var User */ + /** @var User[] $users */ $users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]); $user = $users[0]; if (null === $user) { $io->error(sprintf('No user with the given username %s found in the database!', $user_name)); - return; + return 1; } $io->note('User found!'); @@ -79,7 +79,7 @@ class SetPasswordCommand extends Command $user->getFullName(true), $user->getID())); if (! $proceed) { - return; + return 1; } $success = false; @@ -106,5 +106,6 @@ class SetPasswordCommand extends Command $this->entityManager->flush(); $io->success('Password was set successful! You can now log in using the new password.'); + return 0; } } diff --git a/src/Command/ShowEventLogCommand.php b/src/Command/ShowEventLogCommand.php index 50c0d592..9f368a42 100644 --- a/src/Command/ShowEventLogCommand.php +++ b/src/Command/ShowEventLogCommand.php @@ -64,13 +64,13 @@ class ShowEventLogCommand extends Command $onePage = $input->getOption('onePage'); - $desc = $input->getOption('oldest_first'); - $limit = $input->getOption('count'); - $page = $input->getOption('page'); + $desc = (bool) $input->getOption('oldest_first'); + $limit = (int) $input->getOption('count'); + $page = (int) $input->getOption('page'); $showExtra = $input->getOption('showExtra'); $total_count = $this->repo->count([]); - $max_page = ceil($total_count / $limit); + $max_page = (int) ceil($total_count / $limit); if ($page > $max_page) { $io->error("There is no page ${page}! The maximum page is ${max_page}."); diff --git a/src/Command/UpdateExchangeRatesCommand.php b/src/Command/UpdateExchangeRatesCommand.php index 4db05244..4a0c311f 100644 --- a/src/Command/UpdateExchangeRatesCommand.php +++ b/src/Command/UpdateExchangeRatesCommand.php @@ -68,7 +68,7 @@ class UpdateExchangeRatesCommand extends Command null); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -76,7 +76,7 @@ class UpdateExchangeRatesCommand extends Command if (3 !== strlen($this->base_current)) { $io->error('Choosen Base current is not valid. Check your settings!'); - return; + return 1; } $io->note('Update currency exchange rates with base currency: '.$this->base_current); @@ -121,5 +121,6 @@ class UpdateExchangeRatesCommand extends Command $this->em->flush(); $io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, count($candidates))); + return 0; } } diff --git a/src/Controller/AdminPages/ManufacturerController.php b/src/Controller/AdminPages/ManufacturerController.php index 012041c9..71a0fa5d 100644 --- a/src/Controller/AdminPages/ManufacturerController.php +++ b/src/Controller/AdminPages/ManufacturerController.php @@ -88,7 +88,7 @@ class ManufacturerController extends BaseAdminController /** * @Route("/{id}/export", name="manufacturer_export") * - * @param Supplier $entity + * @param Manufacturer $entity * * @return Response */ diff --git a/src/Controller/AdminPages/StorelocationController.php b/src/Controller/AdminPages/StorelocationController.php index 61656945..69d7de29 100644 --- a/src/Controller/AdminPages/StorelocationController.php +++ b/src/Controller/AdminPages/StorelocationController.php @@ -87,7 +87,7 @@ class StorelocationController extends BaseAdminController /** * @Route("/{id}/export", name="store_location_export") * - * @param AttachmentType $entity + * @param Storelocation $entity * * @return Response */ diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 61bd30c2..8cd4a4aa 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -119,7 +119,7 @@ class UserController extends AdminPages\BaseAdminController /** * @Route("/{id}/export", name="user_export") * - * @param AttachmentType $entity + * @param User $entity * * @return Response */ @@ -167,7 +167,7 @@ class UserController extends AdminPages\BaseAdminController * Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address - * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] + * @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ] * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] * @param bool $img True to return a complete IMG tag False for just the URL diff --git a/src/DataTables/Adapter/FetchJoinORMAdapter.php b/src/DataTables/Adapter/FetchJoinORMAdapter.php index fb5c06e4..c2264a1c 100644 --- a/src/DataTables/Adapter/FetchJoinORMAdapter.php +++ b/src/DataTables/Adapter/FetchJoinORMAdapter.php @@ -70,7 +70,7 @@ class FetchJoinORMAdapter extends ORMAdapter $query = $builder->getQuery(); $event = new ORMAdapterQueryEvent($query); - $state->getDataTable()->getEventDispatcher()->dispatch($event, ORMAdapterEvents::PRE_QUERY); + $state->getDataTable()->getEventDispatcher()->dispatch($event); //Use Doctrine paginator for result iteration $paginator = new Paginator($query); diff --git a/src/DataTables/Adapter/ORMAdapter.php b/src/DataTables/Adapter/ORMAdapter.php index 38c30c7d..be6513ac 100644 --- a/src/DataTables/Adapter/ORMAdapter.php +++ b/src/DataTables/Adapter/ORMAdapter.php @@ -22,6 +22,7 @@ use Omines\DataTablesBundle\Adapter\Doctrine\Event\ORMAdapterQueryEvent; use Omines\DataTablesBundle\Adapter\Doctrine\ORM\AutomaticQueryBuilder; use Omines\DataTablesBundle\Adapter\Doctrine\ORM\QueryBuilderProcessorInterface; use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider; +use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapterEvents; use Omines\DataTablesBundle\Column\AbstractColumn; use Omines\DataTablesBundle\DataTableState; use Omines\DataTablesBundle\Exception\InvalidConfigurationException; diff --git a/src/Entity/Attachments/AttachmentContainingDBElement.php b/src/Entity/Attachments/AttachmentContainingDBElement.php index 1a1c9736..cc447695 100644 --- a/src/Entity/Attachments/AttachmentContainingDBElement.php +++ b/src/Entity/Attachments/AttachmentContainingDBElement.php @@ -37,7 +37,7 @@ abstract class AttachmentContainingDBElement extends NamedDBElement use MasterAttachmentTrait; /** - * @var Attachment[] + * @var Attachment[]|Collection * //TODO * //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element") * diff --git a/src/Entity/LogSystem/DatabaseUpdatedLogEntry.php b/src/Entity/LogSystem/DatabaseUpdatedLogEntry.php index 34594a90..9d0dde59 100644 --- a/src/Entity/LogSystem/DatabaseUpdatedLogEntry.php +++ b/src/Entity/LogSystem/DatabaseUpdatedLogEntry.php @@ -54,7 +54,7 @@ class DatabaseUpdatedLogEntry extends AbstractLogEntry /** * Gets the database version before update. * - * @return int + * @return string */ public function getOldVersion(): string { @@ -64,7 +64,7 @@ class DatabaseUpdatedLogEntry extends AbstractLogEntry /** * Gets the (target) database version after update. * - * @return int + * @return string */ public function getNewVersion(): string { diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 6538d782..7f6969fb 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -233,7 +233,7 @@ class PartLot extends DBElement /** * Sets the part that is stored in this part lot. * - * @param Part|InstockTrait $part + * @param Part $part * * @return PartLot */ diff --git a/src/Entity/Parts/PartTraits/OrderTrait.php b/src/Entity/Parts/PartTraits/OrderTrait.php index f99ed9bc..b359560a 100644 --- a/src/Entity/Parts/PartTraits/OrderTrait.php +++ b/src/Entity/Parts/PartTraits/OrderTrait.php @@ -126,6 +126,7 @@ trait OrderTrait * The orderdetail is assigned to this part. * * @param Orderdetail $orderdetail the orderdetail that should be added + * @return $this */ public function addOrderdetail(Orderdetail $orderdetail): self { @@ -137,8 +138,8 @@ trait OrderTrait /** * Removes the given orderdetail from the list of orderdetails. - * - * @return OrderTrait + * @param Orderdetail $orderdetail + * @return $this */ public function removeOrderdetail(Orderdetail $orderdetail): self { @@ -158,6 +159,7 @@ trait OrderTrait * (if the part has exactly one orderdetails, * set this orderdetails as order orderdetails. * Otherwise, set "no order orderdetails") + * @return $this */ public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): self { diff --git a/src/Entity/PriceInformations/Orderdetail.php b/src/Entity/PriceInformations/Orderdetail.php index 39823ea6..2214d34f 100644 --- a/src/Entity/PriceInformations/Orderdetail.php +++ b/src/Entity/PriceInformations/Orderdetail.php @@ -245,7 +245,7 @@ class Orderdetail extends DBElement * * @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity */ - public function findPriceForQty(float $quantity = 1): ?Pricedetail + public function findPriceForQty(float $quantity = 1.0): ?Pricedetail { if ($quantity <= 0) { return null; diff --git a/src/Form/Type/CurrencyEntityType.php b/src/Form/Type/CurrencyEntityType.php index 674c6796..1b290ba4 100644 --- a/src/Form/Type/CurrencyEntityType.php +++ b/src/Form/Type/CurrencyEntityType.php @@ -69,6 +69,10 @@ class CurrencyEntityType extends StructuralEntityType { //Similar to StructuralEntityType, but we use the currency symbol instead if available + if (!$choice instanceof Currency) { + throw new \InvalidArgumentException('$choice must be an currency object!'); + } + /** @var StructuralDBElement|null $parent */ $parent = $this->options['subentities_of']; diff --git a/src/Security/EntityListeners/ElementPermissionListener.php b/src/Security/EntityListeners/ElementPermissionListener.php index 07794080..3cbfd53a 100644 --- a/src/Security/EntityListeners/ElementPermissionListener.php +++ b/src/Security/EntityListeners/ElementPermissionListener.php @@ -38,7 +38,6 @@ use Doctrine\ORM\Mapping\PreUpdate; use function get_class; use InvalidArgumentException; use ReflectionClass; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Security\Core\Security; /** @@ -59,7 +58,7 @@ class ElementPermissionListener protected $perm_cache; - public function __construct(Security $security, Reader $reader, EntityManagerInterface $em, KernelInterface $kernel) + public function __construct(Security $security, Reader $reader, EntityManagerInterface $em) { $this->security = $security; $this->reader = $reader; diff --git a/src/Security/Voter/AttachmentVoter.php b/src/Security/Voter/AttachmentVoter.php index 6c84c08e..dac97b4b 100644 --- a/src/Security/Voter/AttachmentVoter.php +++ b/src/Security/Voter/AttachmentVoter.php @@ -34,14 +34,17 @@ class AttachmentVoter extends ExtendedVoter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject + * @return bool */ protected function voteOnUser($attribute, $subject, User $user): bool { if ($subject instanceof Attachment) { return $this->resolver->inherit($user, 'parts_attachments', $attribute) ?? false; } + + return false; } /** diff --git a/src/Security/Voter/ExtendedVoter.php b/src/Security/Voter/ExtendedVoter.php index dd4b435e..849c293c 100644 --- a/src/Security/Voter/ExtendedVoter.php +++ b/src/Security/Voter/ExtendedVoter.php @@ -72,8 +72,9 @@ abstract class ExtendedVoter extends Voter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject + * @return bool */ abstract protected function voteOnUser($attribute, $subject, User $user): bool; } diff --git a/src/Security/Voter/GroupVoter.php b/src/Security/Voter/GroupVoter.php index 867ae769..2fbc0b8c 100644 --- a/src/Security/Voter/GroupVoter.php +++ b/src/Security/Voter/GroupVoter.php @@ -33,8 +33,9 @@ class GroupVoter extends ExtendedVoter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject + * @return bool */ protected function voteOnUser($attribute, $subject, User $user): bool { diff --git a/src/Security/Voter/PermissionVoter.php b/src/Security/Voter/PermissionVoter.php index 868a20a9..33438b45 100644 --- a/src/Security/Voter/PermissionVoter.php +++ b/src/Security/Voter/PermissionVoter.php @@ -37,8 +37,8 @@ class PermissionVoter extends ExtendedVoter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject */ protected function voteOnUser($attribute, $subject, User $user): bool { diff --git a/src/Security/Voter/StructureVoter.php b/src/Security/Voter/StructureVoter.php index 8e54e930..d3888017 100644 --- a/src/Security/Voter/StructureVoter.php +++ b/src/Security/Voter/StructureVoter.php @@ -54,6 +54,7 @@ class StructureVoter extends ExtendedVoter //If permission name is null, then the subject is not supported return (null !== $permission_name) && $this->resolver->isValidOperation($permission_name, $attribute); } + return false; } /** @@ -94,8 +95,9 @@ class StructureVoter extends ExtendedVoter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject + * @return bool */ protected function voteOnUser($attribute, $subject, User $user): bool { diff --git a/src/Security/Voter/UserVoter.php b/src/Security/Voter/UserVoter.php index 378993a8..fde4fae4 100644 --- a/src/Security/Voter/UserVoter.php +++ b/src/Security/Voter/UserVoter.php @@ -54,8 +54,9 @@ class UserVoter extends ExtendedVoter * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * - * @param $attribute - * @param $subject + * @param string $attribute + * @param mixed $subject + * @return bool */ protected function voteOnUser($attribute, $subject, User $user): bool { diff --git a/src/Services/ElementTypeNameGenerator.php b/src/Services/ElementTypeNameGenerator.php index ed539e22..b7f488f0 100644 --- a/src/Services/ElementTypeNameGenerator.php +++ b/src/Services/ElementTypeNameGenerator.php @@ -36,6 +36,7 @@ use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; use App\Entity\Parts\PartLot; use App\Entity\Parts\Storelocation; +use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Currency; use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Pricedetail; @@ -43,7 +44,6 @@ use App\Entity\UserSystem\Group; use App\Entity\UserSystem\User; use App\Exceptions\EntityNotSupportedException; use function get_class; -use Proxies\__CG__\App\Entity\Parts\Supplier; use Symfony\Contracts\Translation\TranslatorInterface; class ElementTypeNameGenerator diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 104232b4..64de8f7b 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -133,7 +133,7 @@ class EntityURLGenerator /** * Generates an URL to a page, where info about this entity can be viewed. * - * @param mixed $entity The entity for which the info should be generated + * @param DBElement $entity The entity for which the info should be generated * * @return string The URL to the info page * @@ -223,7 +223,7 @@ class EntityURLGenerator * Generates an URL to a page, where a new entity can be created, that has the same informations as the * given entity (element cloning). * - * @param mixed $entity The entity for which the link should be generated + * @param DBElement $entity The entity for which the link should be generated * * @return string the URL to the page * @@ -241,7 +241,7 @@ class EntityURLGenerator /** * Generates an URL to a page, where all parts are listed, which are contained in the given element. * - * @param mixed $entity The entity for which the link should be generated + * @param DBElement $entity The entity for which the link should be generated * * @return string the URL to the page * diff --git a/src/Services/PermissionResolver.php b/src/Services/PermissionResolver.php index 72aa58c5..eb4dc78f 100644 --- a/src/Services/PermissionResolver.php +++ b/src/Services/PermissionResolver.php @@ -44,7 +44,7 @@ class PermissionResolver /** * PermissionResolver constructor. */ - public function __construct(ParameterBagInterface $params, ContainerInterface $container) + public function __construct(ContainerInterface $container) { $cache_dir = $container->getParameter('kernel.cache_dir'); //Here the cached structure will be saved. diff --git a/symfony.lock b/symfony.lock index 805a9d2c..476133da 100644 --- a/symfony.lock +++ b/symfony.lock @@ -325,9 +325,21 @@ "phpdocumentor/type-resolver": { "version": "0.4.0" }, + "phpstan/extension-installer": { + "version": "1.0.3" + }, "phpstan/phpdoc-parser": { "version": "0.4.2" }, + "phpstan/phpstan": { + "version": "0.12.8" + }, + "phpstan/phpstan-doctrine": { + "version": "0.12.9" + }, + "phpstan/phpstan-symfony": { + "version": "0.12.4" + }, "psr/cache": { "version": "1.0.1" },