Fixed some issues detected by PHPstan.

This commit is contained in:
Jan Böhmer 2020-02-01 17:00:03 +01:00
parent f2ff77a8b3
commit dd1f806c4e
30 changed files with 310 additions and 45 deletions

View file

@ -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",

219
composer.lock generated
View file

@ -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",

12
phpstan.neon Normal file
View file

@ -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/*

View file

@ -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;
}
/**

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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}.");

View file

@ -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;
}
}

View file

@ -88,7 +88,7 @@ class ManufacturerController extends BaseAdminController
/**
* @Route("/{id}/export", name="manufacturer_export")
*
* @param Supplier $entity
* @param Manufacturer $entity
*
* @return Response
*/

View file

@ -87,7 +87,7 @@ class StorelocationController extends BaseAdminController
/**
* @Route("/{id}/export", name="store_location_export")
*
* @param AttachmentType $entity
* @param Storelocation $entity
*
* @return Response
*/

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -37,7 +37,7 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
use MasterAttachmentTrait;
/**
* @var Attachment[]
* @var Attachment[]|Collection
* //TODO
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
*

View file

@ -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
{

View file

@ -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
*/

View file

@ -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
{

View file

@ -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;

View file

@ -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'];

View file

@ -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;

View file

@ -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;
}
/**

View file

@ -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;
}

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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

View file

@ -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
*

View file

@ -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.

View file

@ -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"
},