Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan level 8 #57

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/basic-page-bundle/src/Entity/BasicPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BasicPage implements TranslatableInterface
public const LOCATION_FOOTER = 'footer';

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -46,7 +46,7 @@ class BasicPage implements TranslatableInterface
private $id;

/**
* @var string
* @var string|null
*
* @Assert\Choice(choices = {
* BasicPage::LOCATION_NONE,
Expand All @@ -57,7 +57,7 @@ class BasicPage implements TranslatableInterface
private $location = self::LOCATION_NONE;

/**
* @var bool
* @var bool|null
*
* @ORM\Column(type="boolean")
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BasicPageTranslation implements TranslationInterface
use ORMBehaviors\Translatable\TranslationTrait;

/**
* @var int
* @var string|null
*
* @ORM\Column(type="string", length=5)
*/
Expand All @@ -48,7 +48,7 @@ class BasicPageTranslation implements TranslationInterface
private $id;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @Assert\Length(max=255)
Expand All @@ -57,15 +57,15 @@ class BasicPageTranslation implements TranslationInterface
private $title;

/**
* @var string
* @var string|null
*
* @Gedmo\Slug(fields={"title"}, unique_base="locale")
* @ORM\Column(type="string", nullable=true)
*/
private $slug;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @ORM\Column(type="text")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\Persistence\ManagerRegistry;
use Runroom\BasicPageBundle\Entity\BasicPage;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand All @@ -37,7 +38,7 @@ public function __construct(ManagerRegistry $registry, RequestStack $requestStac

public function findBySlug(string $slug): BasicPage
{
$request = $this->requestStack->getCurrentRequest();
$request = $this->requestStack->getCurrentRequest() ?? new Request();

$query = $this->createQueryBuilder('basic_page')
->leftJoin('basic_page.translations', 'translations', Join::WITH, 'translations.locale = :locale')
Expand Down
12 changes: 6 additions & 6 deletions packages/redirection-bundle/src/Entity/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Redirect
public const TEMPORAL = 302;

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -39,7 +39,7 @@ class Redirect
private $id;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @Assert\Length(max=500)
Expand All @@ -49,7 +49,7 @@ class Redirect
private $source;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @Assert\Length(max=500)
Expand All @@ -60,7 +60,7 @@ class Redirect
private $destination;

/**
* @var int
* @var int|null
*
* @Assert\Choice(choices = {
* Redirect::PERMANENT,
Expand All @@ -71,14 +71,14 @@ class Redirect
private $httpCode = self::PERMANENT;

/**
* @var bool
* @var bool|null
*
* @ORM\Column(type="boolean")
*/
private $automatic = false;

/**
* @var bool
* @var bool|null
*
* @ORM\Column(type="boolean")
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/redirection-bundle/tests/App/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Entity
{
/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -28,14 +28,14 @@ class Entity
private $id;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="string")
*/
private $title;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="string")
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/redirection-bundle/tests/App/Entity/WrongEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class WrongEntity
{
/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -28,7 +28,7 @@ class WrongEntity
private $id;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="string")
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ public function itReturnsRedirect(): void
{
$redirect = $this->repository->findOneBy(['source' => '/redirect']);

self::assertNotNull($redirect->getId());
self::assertSame('/redirect', $redirect->__toString());
self::assertSame('/redirect', $redirect->getSource());
self::assertSame('/target', $redirect->getDestination());
self::assertSame(301, $redirect->getHttpCode());
self::assertTrue($redirect->getPublish());
if (null !== $redirect) {
self::assertNotNull($redirect->getId());
self::assertSame('/redirect', $redirect->__toString());
self::assertSame('/redirect', $redirect->getSource());
self::assertSame('/target', $redirect->getDestination());
self::assertSame(301, $redirect->getHttpCode());
self::assertTrue($redirect->getPublish());
} else {
self::fail('not found redirect');
}
}

/** @test */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class TemplateController
/** @var PageRenderer */
private $renderer;

public function __construct(PageRenderer $renderer = null)
public function __construct(PageRenderer $renderer)
{
$this->renderer = $renderer;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/render-event-bundle/src/Renderer/PageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function renderResponse(string $view, $model = null, Response $response =

/** @var PageRenderEvent */
$event = $this->eventDispatcher->dispatch(
new PageRenderEvent($view, $this->pageViewModel, $response ?? new Response()),
new PageRenderEvent($view, $this->pageViewModel, $response),
PageRenderEvent::EVENT_NAME
);

$response = $event->getResponse();
$response = $event->getResponse() ?? new Response();
if ($response instanceof RedirectResponse || '' !== $response->getContent()) {
return $response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ protected function getCurrentRoute(): string
{
$request = $this->requestStack->getCurrentRequest();

return $request->get('_route', '');
return null !== $request ? $request->get('_route', '') : '';
}

/** @return array<string, string> */
protected function getCurrentRouteParameters(): array
{
$request = $this->requestStack->getCurrentRequest();

$routeParameters = $request->get('_route_params', []);
$routeParameters = null !== $request ? $request->get('_route_params', []) : [];

return array_diff_key($routeParameters, array_flip(self::EXCLUDED_PARAMETERS));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/seo-bundle/src/Behaviors/MetaInformationAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
trait MetaInformationAware
{
/**
* @var EntityMetaInformation
* @var EntityMetaInformation|null
*
* @ORM\OneToOne(targetEntity="Runroom\SeoBundle\Entity\EntityMetaInformation", cascade={"all"})
* @ORM\JoinColumn(referencedColumnName="id")
Expand Down
2 changes: 1 addition & 1 deletion packages/seo-bundle/src/Entity/EntityMetaInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EntityMetaInformation implements TranslatableInterface
use ORMBehaviors\Translatable\TranslatableTrait;

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EntityMetaInformationTranslation implements TranslationInterface
use ORMBehaviors\Translatable\TranslationTrait;

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -37,15 +37,15 @@ class EntityMetaInformationTranslation implements TranslationInterface
private $id;

/**
* @var string
* @var string|null
*
* @Assert\Length(max=255)
* @ORM\Column(type="string", nullable=true)
*/
private $title;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="text", nullable=true)
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/seo-bundle/src/Entity/MetaInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MetaInformation implements TranslatableInterface
use ORMBehaviors\Translatable\TranslatableTrait;

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -39,21 +39,21 @@ class MetaInformation implements TranslatableInterface
private $id;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="string", unique=true)
*/
private $route;

/**
* @var string
* @var string|null
*
* @ORM\Column(type="string")
*/
private $routeName;

/**
* @var MediaInterface
* @var MediaInterface|null
*
* @Assert\Valid
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/seo-bundle/src/Entity/MetaInformationTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MetaInformationTranslation implements TranslationInterface
use ORMBehaviors\Translatable\TranslationTrait;

/**
* @var int
* @var int|null
*
* @ORM\Id
* @ORM\GeneratedValue
Expand All @@ -37,7 +37,7 @@ class MetaInformationTranslation implements TranslationInterface
private $id;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @Assert\Length(max=255)
Expand All @@ -46,7 +46,7 @@ class MetaInformationTranslation implements TranslationInterface
private $title;

/**
* @var string
* @var string|null
*
* @Assert\NotNull
* @ORM\Column(type="text")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function build(MetaInformationProviderInterface $provider, string $route,
private function getMetasForRoute(MetaInformationProviderInterface $provider, string $route): MetaInformation
{
return $this->repository->findOneBy(['route' => $provider->getRouteAlias($route)]) ??
$this->repository->findOneBy(['route' => self::DEFAULT_ROUTE]);
$this->repository->findOneBy(['route' => self::DEFAULT_ROUTE]) ?? new MetaInformation();
}

private function getTitle(?EntityMetaInformation $modelMetas, MetaInformation $routeMetas): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function getCurrentRoute(): string
{
$request = $this->requestStack->getCurrentRequest();

return $request->get('_route', '');
return null !== $request ? $request->get('_route', '') : '';
}

protected function selectProvider(string $route): MetaInformationProviderInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

final class MetaInformationViewModel
{
/** @var string */
/** @var string|null */
private $title;

/** @var string */
/** @var string|null */
private $description;

/** @var MediaInterface */
/** @var MediaInterface|null */
private $image;

public function setTitle(string $title): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
trait Sortable
{
/**
* @var int
* @var int|null
*
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
Expand Down
Loading