activate bleeding edge phpstan rules (#2898)

This commit is contained in:
Kevin Papst
2021-11-02 13:33:21 +01:00
committed by GitHub
parent 36c08b0dea
commit 1b35356f81
32 changed files with 73 additions and 142 deletions

12
composer.lock generated
View File

@@ -6149,16 +6149,16 @@
},
{
"name": "symfony/flex",
"version": "v1.17.1",
"version": "v1.17.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/flex.git",
"reference": "782ef2269622b8349c4bc3dc795fc79d39e8a5b2"
"reference": "0170279814f86648c62aede39b100a343ea29962"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/flex/zipball/782ef2269622b8349c4bc3dc795fc79d39e8a5b2",
"reference": "782ef2269622b8349c4bc3dc795fc79d39e8a5b2",
"url": "https://api.github.com/repos/symfony/flex/zipball/0170279814f86648c62aede39b100a343ea29962",
"reference": "0170279814f86648c62aede39b100a343ea29962",
"shasum": ""
},
"require": {
@@ -6197,7 +6197,7 @@
"description": "Composer plugin for Symfony",
"support": {
"issues": "https://github.com/symfony/flex/issues",
"source": "https://github.com/symfony/flex/tree/v1.17.1"
"source": "https://github.com/symfony/flex/tree/v1.17.2"
},
"funding": [
{
@@ -6213,7 +6213,7 @@
"type": "tidelift"
}
],
"time": "2021-10-14T06:14:48+00:00"
"time": "2021-10-21T08:39:19+00:00"
},
{
"name": "symfony/form",

View File

@@ -2,6 +2,7 @@ includes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
parameters:
tmpDir: %rootDir%/../../../var/cache/phpstan

View File

@@ -123,9 +123,7 @@ class ActivityController extends BaseApiController
if (!\is_array($projects)) {
$projects = explode(',', $projects);
}
if (!empty($projects)) {
$query->setProjects($projects);
}
$query->setProjects($projects);
}
if (!empty($project = $paramFetcher->get('project'))) {

View File

@@ -26,6 +26,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $formDateTime = '';
/**
@@ -36,6 +37,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $formDate = '';
/**
@@ -46,6 +48,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $dateTime = '';
/**
@@ -56,6 +59,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $date = '';
/**
@@ -66,6 +70,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $time = '';
/**
@@ -76,6 +81,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $duration = '';
/**
@@ -86,6 +92,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="boolean")
* @phpstan-ignore-next-line
*/
private $is24hours = true;
/**
@@ -96,6 +103,7 @@ final class I18nConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="DateTime")
* @phpstan-ignore-next-line
*/
private $now;

View File

@@ -26,6 +26,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $trackingMode = 'default';
/**
@@ -36,6 +37,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="string")
* @phpstan-ignore-next-line
*/
private $defaultBeginTime = 'now';
/**
@@ -46,6 +48,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="integer")
* @phpstan-ignore-next-line
*/
private $activeEntriesHardLimit = 1;
/**
@@ -56,6 +59,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="integer")
* @phpstan-ignore-next-line
*/
private $activeEntriesSoftLimit = 1;
/**
@@ -66,6 +70,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="boolean")
* @phpstan-ignore-next-line
*/
private $isAllowFutureTimes = true;
/**
@@ -76,6 +81,7 @@ final class TimesheetConfig
* @Serializer\Expose()
* @Serializer\Groups({"Default"})
* @Serializer\Type(name="boolean")
* @phpstan-ignore-next-line
*/
private $isAllowOverlapping = true;

View File

@@ -123,9 +123,7 @@ class ProjectController extends BaseApiController
if (!\is_array($customers)) {
$customers = explode(',', $customers);
}
if (!empty($customers)) {
$query->setCustomers($customers);
}
$query->setCustomers($customers);
}
if (!empty($customer = $paramFetcher->get('customer'))) {

View File

@@ -23,7 +23,6 @@ use App\Repository\TagRepository;
use App\Repository\TimesheetRepository;
use App\Timesheet\TimesheetService;
use App\Timesheet\TrackingMode\TrackingModeInterface;
use App\Timesheet\TrackingModeService;
use App\Utils\SearchTerm;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\RestBundle\Controller\Annotations as Rest;
@@ -67,10 +66,6 @@ class TimesheetController extends BaseApiController
* @var TagRepository
*/
private $tagRepository;
/**
* @var TrackingModeService
*/
private $trackingModeService;
/**
* @var EventDispatcherInterface
*/
@@ -152,9 +147,7 @@ class TimesheetController extends BaseApiController
if (!\is_array($customers)) {
$customers = explode(',', $customers);
}
if (!empty($customers)) {
$query->setCustomers($customers);
}
$query->setCustomers($customers);
}
if (!empty($customer = $paramFetcher->get('customer'))) {
@@ -165,9 +158,7 @@ class TimesheetController extends BaseApiController
if (!\is_array($projects)) {
$projects = explode(',', $projects);
}
if (!empty($projects)) {
$query->setProjects($projects);
}
$query->setProjects($projects);
}
if (!empty($project = $paramFetcher->get('project'))) {
@@ -178,9 +169,7 @@ class TimesheetController extends BaseApiController
if (!\is_array($activities)) {
$activities = explode(',', $activities);
}
if (!empty($activities)) {
$query->setActivities($activities);
}
$query->setActivities($activities);
}
if (!empty($activity = $paramFetcher->get('activity'))) {

View File

@@ -14,7 +14,6 @@ use App\Event\ActivityBudgetStatisticEvent;
use App\Event\ActivityStatisticEvent;
use App\Model\ActivityBudgetStatisticModel;
use App\Model\ActivityStatistic;
use App\Repository\ActivityRepository;
use App\Repository\TimesheetRepository;
use App\Timesheet\DateTimeFactory;
use DateTime;
@@ -27,13 +26,11 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class ActivityStatisticService
{
private $activityRepository;
private $timesheetRepository;
private $dispatcher;
public function __construct(ActivityRepository $activityRepository, TimesheetRepository $timesheetRepository, EventDispatcherInterface $dispatcher)
public function __construct(TimesheetRepository $timesheetRepository, EventDispatcherInterface $dispatcher)
{
$this->activityRepository = $activityRepository;
$this->timesheetRepository = $timesheetRepository;
$this->dispatcher = $dispatcher;
}

View File

@@ -35,19 +35,14 @@ final class InstallCommand extends Command
public const ERROR_DATABASE = 8;
public const ERROR_MIGRATIONS = 32;
/**
* @var string
*/
private $rootDir;
/**
* @var Connection
*/
private $connection;
public function __construct(string $projectDirectory, Connection $connection)
public function __construct(Connection $connection)
{
parent::__construct();
$this->rootDir = $projectDirectory;
$this->connection = $connection;
}

View File

@@ -117,12 +117,6 @@ final class KimaiImporterCommand extends Command
* @var Customer[]
*/
private $customers = [];
/**
* Instance specific mappings of customer IDs to cache IDs
*
* @var string[]
*/
private $customerIds = [];
/**
* Old Project ID => new Project()
* Global across all instances.
@@ -130,12 +124,6 @@ final class KimaiImporterCommand extends Command
* @var Project[]
*/
private $projects = [];
/**
* Instance specific mappings of project IDs to cache IDs
*
* @var string[]
*/
private $projectIds = [];
/**
* id => [projectId => Activity]
* @var array<Activity[]>
@@ -151,13 +139,6 @@ final class KimaiImporterCommand extends Command
* @var array
*/
private $oldActivities = [];
/**
* If true, unknown Activities will be created globally.
* Default behavior: create project specific activities
*
* @var bool
*/
private $unknownAsGlobal = false;
private $options = [];
@@ -316,8 +297,6 @@ final class KimaiImporterCommand extends Command
$this->teamIds = [];
$this->userIds = [];
$this->customerIds = [];
$this->projectIds = [];
$this->oldActivities = [];
if (!$options['merge-customer']) {
@@ -986,7 +965,6 @@ final class KimaiImporterCommand extends Command
private function setCustomerCache(array $oldCustomer, Customer $customer): void
{
//$this->customerIds[$this->dbPrefix . $oldCustomer['customerID']] = $oldCustomer['customerID'];
$this->customers[$oldCustomer['customerID']] = $customer;
}

View File

@@ -29,19 +29,14 @@ final class UpdateCommand extends Command
public const ERROR_DATABASE = 8;
public const ERROR_MIGRATIONS = 32;
/**
* @var string
*/
private $rootDir;
/**
* @var Connection
*/
private $connection;
public function __construct(string $projectDirectory, Connection $connection)
public function __construct(Connection $connection)
{
parent::__construct();
$this->rootDir = $projectDirectory;
$this->connection = $connection;
}

View File

@@ -19,7 +19,6 @@ use App\Reporting\WeekByUser;
use App\Reporting\WeekByUserForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\TimesheetRepository;
use App\Timesheet\TimesheetStatisticService;
use DateTime;
use Exception;
@@ -35,14 +34,12 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
*/
final class ReportByUserController extends AbstractController
{
private $timesheetRepository;
private $statisticService;
private $projectRepository;
private $activityRepository;
public function __construct(TimesheetRepository $timesheetRepository, TimesheetStatisticService $statisticService, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
public function __construct(TimesheetStatisticService $statisticService, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
$this->timesheetRepository = $timesheetRepository;
$this->statisticService = $statisticService;
$this->projectRepository = $projectRepository;
$this->activityRepository = $activityRepository;

View File

@@ -20,7 +20,6 @@ use App\Reporting\WeeklyUserListForm;
use App\Reporting\YearlyUserList;
use App\Reporting\YearlyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\TimesheetRepository;
use App\Repository\UserRepository;
use App\Timesheet\TimesheetStatisticService;
use Exception;
@@ -35,12 +34,10 @@ use Symfony\Component\Routing\Annotation\Route;
*/
final class ReportUsersListController extends AbstractController
{
private $timesheetRepository;
private $userRepository;
public function __construct(TimesheetRepository $timesheetRepository, UserRepository $userRepository)
public function __construct(UserRepository $userRepository)
{
$this->timesheetRepository = $timesheetRepository;
$this->userRepository = $userRepository;
}

View File

@@ -176,15 +176,13 @@ final class TeamController extends AbstractController
$customerForm->handleRequest($request);
if ($customerForm->isSubmitted() && $customerForm->isValid()) {
if ($customerForm->isValid()) {
try {
$this->repository->saveTeam($team);
$this->flashSuccess('action.update.success');
try {
$this->repository->saveTeam($team);
$this->flashSuccess('action.update.success');
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
}
@@ -194,15 +192,13 @@ final class TeamController extends AbstractController
$projectForm->handleRequest($request);
if ($projectForm->isSubmitted() && $projectForm->isValid()) {
if ($projectForm->isValid()) {
try {
$this->repository->saveTeam($team);
$this->flashSuccess('action.update.success');
try {
$this->repository->saveTeam($team);
$this->flashSuccess('action.update.success');
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
}
}

View File

@@ -14,7 +14,6 @@ use App\Entity\Project;
use App\Event\CustomerStatisticEvent;
use App\Model\CustomerBudgetStatisticModel;
use App\Model\CustomerStatistic;
use App\Repository\CustomerRepository;
use App\Repository\TimesheetRepository;
use App\Timesheet\DateTimeFactory;
use DateTime;
@@ -28,13 +27,11 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class CustomerStatisticService
{
private $repository;
private $timesheetRepository;
private $dispatcher;
public function __construct(CustomerRepository $customerRepository, TimesheetRepository $timesheetRepository, EventDispatcherInterface $dispatcher)
public function __construct(TimesheetRepository $timesheetRepository, EventDispatcherInterface $dispatcher)
{
$this->repository = $customerRepository;
$this->timesheetRepository = $timesheetRepository;
$this->dispatcher = $dispatcher;
}

View File

@@ -49,22 +49,6 @@ abstract class AbstractMigration extends BaseAbstractMigration
return true;
}
/**
* @deprecated since 1.14 - will be removed with 2.0
*/
protected function deactivateForeignKeysOnSqlite()
{
@trigger_error('deactivateForeignKeysOnSqlite() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
}
/**
* @deprecated since 1.14 - will be removed with 2.0
*/
private function activateForeignKeysOnSqlite()
{
@trigger_error('activateForeignKeysOnSqlite() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
}
/**
* @param Schema $schema
* @throws Exception

View File

@@ -30,6 +30,7 @@ class Configuration
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
* @phpstan-ignore-next-line
*/
private $id;

View File

@@ -47,6 +47,7 @@ class Invoice
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @phpstan-ignore-next-line
*/
private $id;

View File

@@ -30,6 +30,7 @@ class Role
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @phpstan-ignore-next-line
*/
private $id;
/**

View File

@@ -30,6 +30,7 @@ class RolePermission
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @phpstan-ignore-next-line
*/
private $id;
/**

View File

@@ -39,6 +39,7 @@ class Tag
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @phpstan-ignore-next-line
*/
private $id;
/**

View File

@@ -32,6 +32,7 @@ class TeamMember
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @phpstan-ignore-next-line
*/
private $id;
/**

View File

@@ -415,9 +415,9 @@ class User implements UserInterface, EquatableInterface, \Serializable
public function getPreference(string $name): ?UserPreference
{
// this code will be triggered, if a currently logged-in user will be deleted and the refreshed from the session
// this code will be triggered, if a currently logged-in user will be deleted and then refreshed from the session
// via one of the UserProvider - e.g. see LdapUserProvider::refreshUser() which calls $user->getPreferenceValue()
if (empty($this->preferences)) {
if ($this->preferences === null) {
return null;
}

View File

@@ -76,11 +76,7 @@ class SelectWithApiDataExtension extends AbstractTypeExtension
$formPrefix = implode('_', array_reverse($formPrefixes));
$formField = $formPrefix;
if (!empty($formField)) {
$formField .= '_';
}
$formField .= $apiData['select'];
$formField = $formPrefix . '_' . $apiData['select'];
$view->vars['attr'] = array_merge($view->vars['attr'], [
'data-form-prefix' => $formPrefix,

View File

@@ -50,6 +50,9 @@ class QuickEntryForm extends AbstractType
foreach ($value->getRows() as $row) {
$project = $row->getProject();
$activity = $row->getActivity();
if ($project === null || $activity === null) {
continue;
}
foreach ($row->getTimesheets() as $timesheet) {
$timesheet->setProject($project);
$timesheet->setActivity($activity);

View File

@@ -21,7 +21,6 @@ use App\Form\Type\TagsType;
use App\Form\Type\UserType;
use App\Form\Type\YesNoType;
use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
@@ -39,15 +38,10 @@ class TimesheetEditForm extends AbstractType
* @var CustomerRepository
*/
private $customers;
/**
* @var ProjectRepository
*/
private $projects;
public function __construct(CustomerRepository $customer, ProjectRepository $project)
public function __construct(CustomerRepository $customer)
{
$this->customers = $customer;
$this->projects = $project;
}
/**

View File

@@ -566,10 +566,6 @@ final class ServiceInvoice
});
foreach ($customerEntries as $id => $settings) {
if (empty($settings['entries'])) {
continue;
}
$customerQuery = clone $query;
$customerQuery->setCustomers([$settings['customer']]);
$model = $this->createModelWithoutEntries($customerQuery);

View File

@@ -64,6 +64,7 @@ class LdapAuthenticationProvider extends UserAuthenticationProvider
// do not update the user here from LDAP, as we don't know if the user can be authenticated
} catch (UsernameNotFoundException $notFound) {
throw $notFound;
/* @phpstan-ignore-next-line */
} catch (\Exception $repositoryProblem) {
$e = new AuthenticationServiceException($repositoryProblem->getMessage(), (int) $repositoryProblem->getCode(), $repositoryProblem);
$e->setToken($token);

View File

@@ -13,10 +13,11 @@ use App\Configuration\ConfigLoaderInterface;
use App\Entity\Configuration;
use App\Form\Model\SystemConfiguration;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Exception\ORMException;
/**
* @extends \Doctrine\ORM\EntityRepository<Configuration>
* @final
*/
class ConfigurationRepository extends EntityRepository implements ConfigLoaderInterface
{
@@ -26,14 +27,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
public function clearCache()
{
static::$cacheByPrefix = [];
static::$cacheAll = [];
static::$initialized = false;
self::$cacheByPrefix = [];
self::$cacheAll = [];
self::$initialized = false;
}
private function prefillCache()
{
if (static::$initialized === true) {
if (self::$initialized === true) {
return;
}
@@ -41,13 +42,13 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
$configs = $this->findAll();
foreach ($configs as $config) {
$key = substr($config->getName(), 0, strpos($config->getName(), '.'));
if (!\array_key_exists($key, static::$cacheByPrefix)) {
static::$cacheByPrefix[$key] = [];
if (!\array_key_exists($key, self::$cacheByPrefix)) {
self::$cacheByPrefix[$key] = [];
}
static::$cacheByPrefix[$key][] = $config;
static::$cacheAll[] = $config;
self::$cacheByPrefix[$key][] = $config;
self::$cacheAll[] = $config;
}
static::$initialized = true;
self::$initialized = true;
}
public function saveConfiguration(Configuration $configuration)
@@ -67,14 +68,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
$this->prefillCache();
if (null === $prefix) {
return static::$cacheAll;
return self::$cacheAll;
}
if (!\array_key_exists($prefix, static::$cacheByPrefix)) {
if (!\array_key_exists($prefix, self::$cacheByPrefix)) {
return [];
}
return static::$cacheByPrefix[$prefix];
return self::$cacheByPrefix[$prefix];
}
public function saveSystemConfiguration(SystemConfiguration $model)

View File

@@ -59,7 +59,7 @@ class UserTeamProjects extends SimpleWidget implements AuthorizedWidget, UserWid
foreach ($user->getTeams() as $team) {
/** @var Project $project */
foreach ($team->getProjects() as $project) {
if (!isset($projects[$project->getId()])) {
if (!isset($teamProjects[$project->getId()])) {
$teamProjects[$project->getId()] = $project;
}
}

View File

@@ -31,7 +31,6 @@ class InstallCommandTest extends KernelTestCase
$container = self::$kernel->getContainer();
$this->application->add(new InstallCommand(
$container->getParameter('kernel.project_dir'),
$container->get('doctrine')->getConnection()
));
}

View File

@@ -34,7 +34,6 @@ class UpdateCommandTest extends KernelTestCase
$container = self::$kernel->getContainer();
$this->application->add(new UpdateCommand(
$container->getParameter('kernel.project_dir'),
$container->get('doctrine')->getConnection()
));