Skip to content

Commit

Permalink
Merge pull request #244 from Art4/phpstan-level-1
Browse files Browse the repository at this point in the history
Fix 8 errors and reach PHPStan level 1
  • Loading branch information
holema authored Sep 10, 2024
2 parents 1ace325 + af75374 commit 20dd4b0
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 0
level: 1
paths:
- bin/
- config/
Expand Down
19 changes: 15 additions & 4 deletions src/Controller/TeamMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Throwable;

class TeamMemberController extends BaseController
{
Expand Down Expand Up @@ -227,9 +228,14 @@ public function mitgliederAdd(
$errors = array();
if ($form->isSubmitted() && $form->isValid()) {
$newMembers = $form->getData();
$lines = explode("\n", $newMembers['member']);

if (!empty($lines)) {
try {
$lines = explode("\n", $newMembers['member']);
} catch (Throwable $th) {
$lines = [];
}

if (count($lines) > 0) {
foreach ($lines as $line) {
$newMember = trim($line);
$newUser = $inviteService->newUser($newMember);
Expand Down Expand Up @@ -325,9 +331,14 @@ public function teamMemberCreate(

if ($form->isSubmitted() && $form->isValid()) {
$newMembers = $form->getData();
$lines = explode("\n", $newMembers['member']);

if (!empty($lines)) {
try {
$lines = explode("\n", $newMembers['member']);
} catch (Throwable $th) {
$lines = [];
}

if (count($lines) > 0) {
foreach ($lines as $line) {
$newMember = trim($line);
$user = $inviteService->newUser($newMember);
Expand Down
11 changes: 5 additions & 6 deletions src/Repository/AuditTomZieleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Repository;

use App\Entity\AuditTomZiele;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -15,10 +14,10 @@
class AuditTomZieleRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, AuditTomZiele::class);
protected readonly ManagerRegistry $registry,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $teamRepository, AuditTomZiele::class);
}
}
5 changes: 2 additions & 3 deletions src/Repository/DatenweitergabeGrundlagenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Repository;

use App\Entity\DatenweitergabeGrundlagen;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -16,9 +15,9 @@ class DatenweitergabeGrundlagenRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, DatenweitergabeGrundlagen::class);
parent::__construct($this->registry, $teamRepository, DatenweitergabeGrundlagen::class);
}
}
6 changes: 2 additions & 4 deletions src/Repository/DatenweitergabeStandRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Repository;

use App\Entity\DatenweitergabeStand;
use App\Entity\Team;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -17,9 +15,9 @@ class DatenweitergabeStandRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, DatenweitergabeStand::class);
parent::__construct($this->registry, $teamRepository, DatenweitergabeStand::class);
}
}
6 changes: 3 additions & 3 deletions src/Repository/PresetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
abstract class PresetRepository extends ServiceEntityRepository
{
public function __construct(
ManagerRegistry $registry,
TeamRepository $teamRepository,
string $entityClass
ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
string $entityClass
)
{
parent::__construct($registry, $entityClass);
Expand Down
6 changes: 2 additions & 4 deletions src/Repository/ProdukteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Repository;

use App\Entity\Produkte;
use App\Entity\Team;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -17,9 +15,9 @@ class ProdukteRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, Produkte::class);
parent::__construct($this->registry, $teamRepository, Produkte::class);
}
}
6 changes: 2 additions & 4 deletions src/Repository/VVTGrundlageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Repository;

use App\Entity\Team;
use App\Entity\VVTGrundlage;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -17,9 +15,9 @@ class VVTGrundlageRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository,VVTGrundlage::class);
parent::__construct($this->registry, $teamRepository,VVTGrundlage::class);
}
}
5 changes: 2 additions & 3 deletions src/Repository/VVTPersonenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Entity\Team;
use App\Entity\VVTPersonen;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -17,10 +16,10 @@ class VVTPersonenRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, VVTPersonen::class);
parent::__construct($this->registry, $teamRepository, VVTPersonen::class);
}

public function findByTeam(Team $team)
Expand Down
5 changes: 2 additions & 3 deletions src/Repository/VVTRisikenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Repository;

use App\Entity\VVTRisiken;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -16,9 +15,9 @@ class VVTRisikenRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, VVTRisiken::class);
parent::__construct($this->registry, $teamRepository, VVTRisiken::class);
}
}
7 changes: 2 additions & 5 deletions src/Repository/VVTStatusRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace App\Repository;

use App\Entity\Team;
use App\Entity\VVTStatus;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -18,9 +15,9 @@ class VVTStatusRepository extends PresetRepository
{
public function __construct(
protected readonly ManagerRegistry $registry,
protected readonly TeamRepository $teamRepository,
TeamRepository $teamRepository,
)
{
parent::__construct($this->registry, $this->teamRepository, VVTStatus::class);
parent::__construct($this->registry, $teamRepository, VVTStatus::class);
}
}
2 changes: 0 additions & 2 deletions src/Service/ApproveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class ApproveService
Expand All @@ -20,7 +19,6 @@ class ApproveService

public function __construct(
EntityManagerInterface $entityManager,
FormFactoryInterface $formBuilder,
private TranslatorInterface $translator,
)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Service/CronService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use App\Entity\AkademieBuchungen;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

Expand All @@ -21,7 +20,6 @@ class CronService
{
public function __construct(
private EntityManagerInterface $em,
FormFactoryInterface $formBuilder,
private LoggerInterface $logger,
private TranslatorInterface $translator,
private NotificationService $notificationService,
Expand Down
12 changes: 9 additions & 3 deletions src/Service/TeamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use App\Repository\VVTRisikenRepository;
use App\Repository\VVTStatusRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -51,6 +52,9 @@ public function __construct(

}

/**
* @throws Exception If $type is not a valid team type
*/
public function create($type, $id, Team $team): object
{
switch ($type) {
Expand Down Expand Up @@ -118,8 +122,7 @@ public function create($type, $id, Team $team): object
}
break;
default:

break;
throw new Exception(sprintf('`%s` is an invalid team type.', strval($type)), 1);

}

Expand All @@ -129,6 +132,9 @@ public function create($type, $id, Team $team): object
return $data1;
}

/**
* @throws Exception If $type is not a valid team type
*/
public function delete($type, $id): ?object
{
switch ($type) {
Expand Down Expand Up @@ -161,7 +167,7 @@ public function delete($type, $id): ?object
break;

default:
break;
throw new Exception(sprintf('`%s` is an invalid team type.', strval($type)), 1);

}

Expand Down

0 comments on commit 20dd4b0

Please sign in to comment.