Skip to content

Commit

Permalink
Bump psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Mar 29, 2021
1 parent 0c1952c commit cd9f5fc
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 61 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="6" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php" errorBaseline="psalm-baseline.xml">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="5" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
14 changes: 9 additions & 5 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ final public function getBatchActions(): array
final public function getRoutes(): RouteCollectionInterface
{
$this->buildRoutes();
\assert($this->routes !== null);

return $this->routes;
}
Expand Down Expand Up @@ -906,8 +907,6 @@ final public function attachAdminClass(FieldDescriptionInterface $fieldDescripti
}

/**
* @param string|int|null $id
*
* @phpstan-return T|null
*/
final public function getObject($id): ?object
Expand Down Expand Up @@ -968,16 +967,14 @@ final public function getDatagrid(): DatagridInterface
return $this->datagrid;
}

/**
* @phpstan-param AdminInterface<object>|null $childAdmin
*/
final public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface
{
if ($this->isChild()) {
return $this->getParent()->getSideMenu($action, $this);
}

$this->buildTabMenu($action, $childAdmin);
\assert($this->menu !== null);

return $this->menu;
}
Expand Down Expand Up @@ -1101,6 +1098,7 @@ final public function getParentFieldDescription(): FieldDescriptionInterface
static::class
));
}
\assert($this->parentFieldDescription !== null);

return $this->parentFieldDescription;
}
Expand Down Expand Up @@ -1132,6 +1130,7 @@ final public function getSubject(): object
static::class
));
}
\assert($this->subject !== null);

return $this->subject;
}
Expand Down Expand Up @@ -1598,6 +1597,7 @@ public function id(object $model): ?string
final public function getShow(): FieldDescriptionCollection
{
$this->buildShow();
\assert($this->show !== null);

return $this->show;
}
Expand Down Expand Up @@ -1883,6 +1883,7 @@ final public function getTemplateRegistry(): MutableTemplateRegistryInterface
if (false === $this->hasTemplateRegistry()) {
throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class));
}
\assert($this->templateRegistry !== null);

return $this->templateRegistry;
}
Expand Down Expand Up @@ -2408,6 +2409,9 @@ private function buildRoutes(): void
}
}

/**
* @phpstan-param AdminInterface<object>|null $childAdmin
*/
private function buildTabMenu(string $action, ?AdminInterface $childAdmin = null): void
{
if ($this->loaded['tab_menu']) {
Expand Down
5 changes: 4 additions & 1 deletion src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function getUniqid(): string;
public function getClassnameLabel(): string;

/**
* @param mixed $id
* @param string|int|null $id
*
* @phpstan-return T|null
*/
Expand Down Expand Up @@ -483,6 +483,9 @@ public function getBaseRoutePattern(): string;
*/
public function getBaseRouteName(): string;

/**
* @param AdminInterface<object>|null $childAdmin
*/
public function getSideMenu(string $action, ?self $childAdmin = null): ItemInterface;

public function addParentAssociationMapping(string $code, string $value): void;
Expand Down
3 changes: 3 additions & 0 deletions src/Builder/RouteBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
*/
interface RouteBuilderInterface
{
/**
* @param AdminInterface<object> $admin
*/
public function build(AdminInterface $admin, RouteCollectionInterface $collection): void;
}
1 change: 1 addition & 0 deletions src/DependencyInjection/Admin/AbstractTaggedAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ final public function getFilterPersister(): FilterPersisterInterface
if (!$this->hasFilterPersister()) {
throw new \LogicException(sprintf('Admin "%s" has no filter persister.', static::class));
}
\assert($this->filterPersister !== null);

return $this->filterPersister;
}
Expand Down
1 change: 1 addition & 0 deletions src/Mapper/BaseGroupedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ protected function getCurrentGroupName(): string
]);
}
}
\assert($this->currentGroup !== null);

return $this->currentGroup;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Model/AuditManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function getReader(string $class): AuditReaderInterface
{
foreach ($this->readers as $readerId => $classes) {
if (\in_array($class, $classes, true)) {
return $this->container->get($readerId);
$reader = $this->container->get($readerId);
\assert($reader instanceof AuditReaderInterface);

return $reader;
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/Route/PathInfoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function __construct(AuditManagerInterface $manager)
$this->manager = $manager;
}

/**
* @param AdminInterface<object> $admin
*/
public function build(AdminInterface $admin, RouteCollectionInterface $collection): void
{
$collection->add('list');
Expand Down
2 changes: 2 additions & 0 deletions src/Route/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public function restore(string $name): RouteCollectionInterface

/**
* @param string|string[] $routeList
*
* @return static
*/
public function clearExcept($routeList): RouteCollectionInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function getName(): string
/**
* Get the identifiers as a string that is safe to use in a url.
*
* @return string string representation of the id that is safe to use in a url
* @return string|null representation of the id that is safe to use in a url
*
* @phpstan-template T of object
* @phpstan-param T $model
* @phpstan-param AdminInterface<T>|null $admin
*/
public function getUrlSafeIdentifier(object $model, ?AdminInterface $admin = null): string
public function getUrlSafeIdentifier(object $model, ?AdminInterface $admin = null): ?string
{
if (null === $admin) {
/** @phpstan-var class-string $class */
Expand Down
2 changes: 1 addition & 1 deletion tests/Action/AppendFormFieldElementActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testAppendFormFieldElementAction(): void
'context' => 'list',
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]);

$modelManager = $this->createStub(ModelManagerInterface::class);
$modelManager = $this->createMock(ModelManagerInterface::class);
$formView = new FormView();
$form = $this->createStub(Form::class);
$renderer = $this->configureFormRenderer();
Expand Down
6 changes: 3 additions & 3 deletions tests/Action/RetrieveAutocompleteItemsActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function configureAutocompleteItemsDatagrid(): MockObject

private function configureFormConfig(string $field, bool $disabled = false): void
{
$form = $this->createStub(Form::class);
$form = $this->createMock(Form::class);
$formType = $this->createStub(Form::class);
$formConfig = $this->createStub(FormConfigInterface::class);

Expand All @@ -285,7 +285,7 @@ private function configureFormConfig(string $field, bool $disabled = false): voi

private function configureFormConfigComplexProperty(string $field): void
{
$form = $this->createStub(Form::class);
$form = $this->createMock(Form::class);
$formType = $this->createStub(Form::class);
$formConfig = $this->createStub(FormConfigInterface::class);

Expand All @@ -306,7 +306,7 @@ private function configureFormConfigComplexProperty(string $field): void

private function configureFormConfigComplexPropertyArray(string $field): void
{
$form = $this->createStub(Form::class);
$form = $this->createMock(Form::class);
$formType = $this->createStub(Form::class);
$formConfig = $this->createStub(FormConfigInterface::class);

Expand Down
2 changes: 1 addition & 1 deletion tests/Action/RetrieveFormFieldElementActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testRetrieveFormFieldElementAction(): void
'context' => 'list',
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]);

$modelManager = $this->createStub(ModelManagerInterface::class);
$modelManager = $this->createMock(ModelManagerInterface::class);
$formView = new FormView();
$form = $this->createMock(Form::class);
$formBuilder = $this->createStub(FormBuilder::class);
Expand Down
12 changes: 6 additions & 6 deletions tests/Action/SetObjectFieldValueActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testSetObjectFieldValueAction(): void
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testSetObjectFieldValueActionWithDate($timezone, \DateTimeZone $
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down Expand Up @@ -235,7 +235,7 @@ public function testSetObjectFieldValueActionOnARelationField(): void
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down Expand Up @@ -319,7 +319,7 @@ public function testSetObjectFieldEditableMultipleValue(): void
], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down Expand Up @@ -371,7 +371,7 @@ public function testSetObjectFieldTransformed(): void
});

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down Expand Up @@ -425,7 +425,7 @@ public function testSetObjectFieldOverrideTransformer(): void
});

$fieldDescription = $this->createStub(FieldDescriptionInterface::class);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$templateRegistry = $this->createMock(TemplateRegistryInterface::class);
$container = new Container();

$this->admin->method('getObject')->with(42)->willReturn($object);
Expand Down
6 changes: 3 additions & 3 deletions tests/Admin/AdminHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testItThrowsExceptionWhenDoesNotFindTheFullPath(): void

public function testAppendFormFieldElement(): void
{
$admin = $this->createStub(AdminInterface::class);
$admin = $this->createMock(AdminInterface::class);
$admin
->method('getClass')
->willReturn(Foo::class);
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testAppendFormFieldElement(): void

public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndNoCollectionClass(): void
{
$admin = $this->createStub(AdminInterface::class);
$admin = $this->createMock(AdminInterface::class);
$admin
->method('getClass')
->willReturn(Foo::class);
Expand Down Expand Up @@ -341,7 +341,7 @@ public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndN

public function testAppendFormFieldElementWithCollection(): void
{
$admin = $this->createStub(AdminInterface::class);
$admin = $this->createMock(AdminInterface::class);
$admin
->method('getClass')
->willReturn(Foo::class);
Expand Down
16 changes: 8 additions & 8 deletions tests/Admin/BreadcrumbsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public function testChildGetBreadCrumbs(): void
{
$action = 'my_action';
$breadcrumbsBuilder = new BreadcrumbsBuilder(['child_admin_route' => 'show']);
$admin = $this->createStub(AdminInterface::class);
$admin = $this->createMock(AdminInterface::class);
$admin->method('isChild')->willReturn(false);

$admin->method('getMenuFactory')->willReturn(new MenuFactory());
$labelTranslatorStrategy = $this->createStub(LabelTranslatorStrategyInterface::class);

$routeGenerator = $this->createStub(RouteGeneratorInterface::class);
$routeGenerator = $this->createMock(RouteGeneratorInterface::class);
$routeGenerator->method('generate')->with('sonata_admin_dashboard')->willReturn('/dashboard');

$admin->method('getRouteGenerator')->willReturn($routeGenerator);
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testChildGetBreadCrumbs(): void
]);

$admin->method('getCurrentChildAdmin')->willReturn($childAdmin);
$request = $this->createStub(Request::class);
$request = $this->createMock(Request::class);
$request->method('get')->with('slug')->willReturn('my-object');

$admin->method('getIdParameter')->willReturn('slug');
Expand Down Expand Up @@ -153,13 +153,13 @@ public function testBuildBreadcrumbs(string $action): void
$breadcrumbsBuilder = new BreadcrumbsBuilder();

$menu = $this->createMock(ItemInterface::class);
$menuFactory = $this->createStub(MenuFactory::class);
$menuFactory = $this->createMock(MenuFactory::class);
$menuFactory->method('createItem')->with('root')->willReturn($menu);
$admin = $this->createStub(AdminInterface::class);
$admin = $this->createMock(AdminInterface::class);
$admin->method('getMenuFactory')->willReturn($menuFactory);
$labelTranslatorStrategy = $this->createStub(LabelTranslatorStrategyInterface::class);

$routeGenerator = $this->createStub(RouteGeneratorInterface::class);
$routeGenerator = $this->createMock(RouteGeneratorInterface::class);
$routeGenerator->method('generate')->with('sonata_admin_dashboard')->willReturn('/dashboard');
$admin->method('getRouteGenerator')->willReturn($routeGenerator);

Expand Down Expand Up @@ -200,7 +200,7 @@ public function testBuildBreadcrumbs(string $action): void
['my_class_name_create', 'breadcrumb', 'link', 'create my object'],
]);

$childAdmin = $this->createStub(AdminInterface::class);
$childAdmin = $this->createMock(AdminInterface::class);
$childAdmin->method('getTranslationDomain')->willReturn('ChildBundle');
$childAdmin->method('getLabelTranslatorStrategy')->willReturn($labelTranslatorStrategy);
$childAdmin->method('getClassnameLabel')->willReturn('my_child_class_name');
Expand All @@ -223,7 +223,7 @@ public function testBuildBreadcrumbs(string $action): void
$menu->expects($this->never())->method('setUri');
}

$request = $this->createStub(Request::class);
$request = $this->createMock(Request::class);
$request->method('get')->with('slug')->willReturn('my-object');

$admin->method('getIdParameter')->willReturn('slug');
Expand Down
Loading

0 comments on commit cd9f5fc

Please sign in to comment.