Code improvements (#1649)

* use global namespace for faster lookups
* phpstan level 5
This commit is contained in:
Kevin Papst
2020-04-19 14:37:14 +02:00
committed by GitHub
parent 7b25e9acaf
commit 0f3fa8fdbe
183 changed files with 604 additions and 574 deletions

View File

@@ -275,7 +275,7 @@ class ActivityRepository extends EntityRepository
$where = $qb->expr()->andX();
if (in_array($query->getVisibility(), [ActivityQuery::SHOW_VISIBLE, ActivityQuery::SHOW_HIDDEN])) {
if (\in_array($query->getVisibility(), [ActivityQuery::SHOW_VISIBLE, ActivityQuery::SHOW_HIDDEN])) {
if (!$query->isGlobalsOnly()) {
$where->add(
$qb->expr()->orX(

View File

@@ -36,7 +36,7 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
static::$cacheByPrefix = [];
foreach ($configs as $config) {
$key = substr($config->getName(), 0, strpos($config->getName(), '.'));
if (!array_key_exists($key, static::$cacheByPrefix)) {
if (!\array_key_exists($key, static::$cacheByPrefix)) {
static::$cacheByPrefix[$key] = [];
}
static::$cacheByPrefix[$key][] = $config;
@@ -56,7 +56,7 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
return static::$cacheAll;
}
if (!array_key_exists($prefix, static::$cacheByPrefix)) {
if (!\array_key_exists($prefix, static::$cacheByPrefix)) {
return [];
}
@@ -84,7 +84,7 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
}
// allow to use entity types
if (is_object($value) && method_exists($value, 'getId')) {
if (\is_object($value) && method_exists($value, 'getId')) {
$value = $value->getId();
}

View File

@@ -47,7 +47,7 @@ final class InvoiceDocumentRepository
*/
public function findAll()
{
$base = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
$base = \dirname(\dirname(__DIR__)) . DIRECTORY_SEPARATOR;
$documents = [];

View File

@@ -58,16 +58,16 @@ class InvoiceRepository extends EntityRepository
public function getCounterForMonth(\DateTime $date): int
{
$start = (clone $date)->setDate($date->format('Y'), $date->format('n'), 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate($date->format('Y'), $date->format('n'), $date->format('t'))->setTime(23, 59, 59);
$start = (clone $date)->setDate((int) $date->format('Y'), (int) $date->format('n'), 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate((int) $date->format('Y'), (int) $date->format('n'), (int) $date->format('t'))->setTime(23, 59, 59);
return $this->getCounterFor($start, $end);
}
public function getCounterForYear(\DateTime $date): int
{
$start = (clone $date)->setDate($date->format('Y'), 1, 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate($date->format('Y'), 12, 31)->setTime(23, 59, 59);
$start = (clone $date)->setDate((int) $date->format('Y'), 1, 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate((int) $date->format('Y'), 12, 31)->setTime(23, 59, 59);
return $this->getCounterFor($start, $end);
}

View File

@@ -63,7 +63,7 @@ final class UserIdLoader implements LoaderInterface
}
}
if (count($teamIds) > 0) {
if (\count($teamIds) > 0) {
$qb = $em->createQueryBuilder();
$qb->select('PARTIAL t.{id}', 'teamlead')
->from(Team::class, 't')

View File

@@ -271,7 +271,7 @@ class ProjectRepository extends EntityRepository
$qb->addOrderBy($orderBy, $query->getOrder());
if (in_array($query->getVisibility(), [ProjectQuery::SHOW_VISIBLE, ProjectQuery::SHOW_HIDDEN])) {
if (\in_array($query->getVisibility(), [ProjectQuery::SHOW_VISIBLE, ProjectQuery::SHOW_HIDDEN])) {
$qb
->andWhere($qb->expr()->eq('p.visible', ':visible'))
->andWhere($qb->expr()->eq('c.visible', ':customer_visible'))

View File

@@ -26,14 +26,14 @@ final class ActivityFormTypeQuery extends BaseFormTypeQuery
public function __construct($activity = null, $project = null)
{
if (null !== $activity) {
if (!is_array($activity)) {
if (!\is_array($activity)) {
$activity = [$activity];
}
$this->setActivities($activity);
}
if (null !== $project) {
if (!is_array($project)) {
if (!\is_array($project)) {
$project = [$project];
}
$this->setProjects($project);

View File

@@ -76,7 +76,7 @@ class ActivityQuery extends ProjectQuery
*/
public function getProject()
{
if (count($this->projects) > 0) {
if (\count($this->projects) > 0) {
return $this->projects[0];
}

View File

@@ -44,7 +44,7 @@ abstract class BaseFormTypeQuery
*/
public function getActivity()
{
if (count($this->activities) > 0) {
if (\count($this->activities) > 0) {
return $this->activities[0];
}
@@ -107,7 +107,7 @@ abstract class BaseFormTypeQuery
*/
public function getProject()
{
if (count($this->projects) > 0) {
if (\count($this->projects) > 0) {
return $this->projects[0];
}
@@ -173,7 +173,7 @@ abstract class BaseFormTypeQuery
*/
public function getCustomer()
{
if (count($this->customers) > 0) {
if (\count($this->customers) > 0) {
return $this->customers[0];
}

View File

@@ -193,7 +193,7 @@ class BaseQuery
*/
public function setOrder($order)
{
if (in_array($order, [self::ORDER_ASC, self::ORDER_DESC])) {
if (\in_array($order, [self::ORDER_ASC, self::ORDER_DESC])) {
$this->order = $order;
}
@@ -264,7 +264,7 @@ class BaseQuery
{
foreach ($errors as $error) {
$key = $error->getOrigin()->getName();
if (array_key_exists($key, $this->defaults)) {
if (\array_key_exists($key, $this->defaults)) {
$this->set($key, $this->defaults[$key]);
}
}

View File

@@ -27,7 +27,7 @@ final class CustomerFormTypeQuery extends BaseFormTypeQuery
public function __construct($customer = null)
{
if (null !== $customer) {
if (!is_array($customer)) {
if (!\is_array($customer)) {
$customer = [$customer];
}
$this->setCustomers($customer);

View File

@@ -30,14 +30,14 @@ final class ProjectFormTypeQuery extends BaseFormTypeQuery
public function __construct($project = null, $customer = null)
{
if (null !== $project) {
if (!is_array($project)) {
if (!\is_array($project)) {
$project = [$project];
}
$this->setProjects($project);
}
if (null !== $customer) {
if (!is_array($customer)) {
if (!\is_array($customer)) {
$customer = [$customer];
}
$this->setCustomers($customer);

View File

@@ -46,7 +46,7 @@ class ProjectQuery extends BaseQuery implements VisibilityInterface
*/
public function getCustomer()
{
if (count($this->customers) > 0) {
if (\count($this->customers) > 0) {
return $this->customers[0];
}

View File

@@ -119,7 +119,7 @@ class TimesheetQuery extends ActivityQuery
*/
public function getActivity()
{
if (count($this->activities) > 0) {
if (\count($this->activities) > 0) {
return $this->activities[0];
}
@@ -189,7 +189,7 @@ class TimesheetQuery extends ActivityQuery
public function setState($state)
{
$state = (int) $state;
if (in_array($state, [self::STATE_ALL, self::STATE_RUNNING, self::STATE_STOPPED], true)) {
if (\in_array($state, [self::STATE_ALL, self::STATE_RUNNING, self::STATE_STOPPED], true)) {
$this->state = $state;
}
@@ -211,7 +211,7 @@ class TimesheetQuery extends ActivityQuery
public function setExported($exported)
{
$exported = (int) $exported;
if (in_array($exported, [self::STATE_ALL, self::STATE_EXPORTED, self::STATE_NOT_EXPORTED], true)) {
if (\in_array($exported, [self::STATE_ALL, self::STATE_EXPORTED, self::STATE_NOT_EXPORTED], true)) {
$this->exported = $exported;
}

View File

@@ -24,7 +24,7 @@ trait VisibilityTrait
public function setVisibility($visibility)
{
$visibility = (int) $visibility;
if (in_array($visibility, VisibilityInterface::ALLOWED_VISIBILITY_STATES, true)) {
if (\in_array($visibility, VisibilityInterface::ALLOWED_VISIBILITY_STATES, true)) {
$this->visibility = $visibility;
}

View File

@@ -36,7 +36,7 @@ final class TimesheetInvoiceItemRepository implements InvoiceItemRepositoryInter
}
/**
* @param InvoiceItemInterface[] $invoiceItems
* @param Timesheet[] $invoiceItems
*/
public function setExported(array $invoiceItems)
{

View File

@@ -185,7 +185,7 @@ class TimesheetRepository extends EntityRepository
{
switch ($type) {
case self::STATS_QUERY_ACTIVE:
return count($this->getActiveEntries($user));
return \count($this->getActiveEntries($user));
case self::STATS_QUERY_MONTHLY:
return $this->getMonthlyStats($user, $begin, $end);
@@ -524,7 +524,7 @@ class TimesheetRepository extends EntityRepository
// -> all entries, including the new one must not exceed the $limit
$limit = $hardLimit - 1;
if (count($activeEntries) > $limit) {
if (\count($activeEntries) > $limit) {
$i = 1;
foreach ($activeEntries as $activeEntry) {
if ($i > $limit) {

View File

@@ -71,7 +71,7 @@ class UserRepository extends EntityRepository implements UserLoaderInterface
*/
public function findOneBy(array $criteria, array $orderBy = null)
{
if (count($criteria) == 1 && isset($criteria['username'])) {
if (\count($criteria) == 1 && isset($criteria['username'])) {
return $this->loadUserByUsername($criteria['username']);
}