Skip to content

Commit

Permalink
Bump PhpStan Level to 6: Add missing param/return types (pimcore#13869)
Browse files Browse the repository at this point in the history
* Add missing param/return types

* setValuesToDocument: Rename $page param to $document

* Add missing param/return types

* Fix PhpStan errors

* Add missing param/return types

* Update auf PhpStan 1.9.5

* Add missing param/return types

* Fix PhpStan

* Fix PhpStan

* Fix PhpStan

* Fix PhpStan

* Add missing return types

* Add missing param/return types

* Review

* Fix wrong return types

* Use return type self

* Use return type static

* Fix PhpStan

* Remove changes from tests (separate PR)

* Bump PhpStan Level to 6 with checkGenericClassInNonGenericObjectType/checkMissingIterableValueType = false

* Fix Codeception

* Bump Twig version to ^3.3.9 to have PhpDocs for SecurityPolicyInterface

* Add missing param/return types

* Add missing param/return types

* make params optional

* Pimcore\Tool\Console: Fix types

* Add missing return types

Co-authored-by: Christian Fasching <[email protected]>
  • Loading branch information
blankse and fashxp authored Jan 13, 2023
1 parent d006c76 commit bbcc422
Show file tree
Hide file tree
Showing 882 changed files with 2,555 additions and 3,037 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ public function updateAction(Request $request): JsonResponse
/**
* @Route("/webdav{path}", name="pimcore_admin_webdav", requirements={"path"=".*"})
*/
public function webdavAction()
public function webdavAction(): void
{
$homeDir = Asset::getById(1);

Expand Down Expand Up @@ -1593,7 +1593,7 @@ public function getDocumentThumbnailAction(Request $request): BinaryFileResponse
return $response;
}

protected function addThumbnailCacheHeaders(Response $response)
protected function addThumbnailCacheHeaders(Response $response): void
{
$lifetime = 300;
$date = new \DateTime('now');
Expand Down Expand Up @@ -2475,7 +2475,7 @@ public function importServerFilesAction(Request $request): JsonResponse
]);
}

protected function checkForPharStreamWrapper($path)
protected function checkForPharStreamWrapper(string $path): void
{
if (stripos($path, 'phar://') !== false) {
throw $this->createAccessDeniedException('Using PHAR files is not allowed!');
Expand Down Expand Up @@ -2815,7 +2815,7 @@ public function deleteImageFeaturesAction(Request $request): JsonResponse
throw $this->createAccessDeniedHttpException();
}

public function onKernelControllerEvent(ControllerEvent $event)
public function onKernelControllerEvent(ControllerEvent $event): void
{
if (!$event->isMainRequest()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public function gridSaveColumnConfigAction(Request $request): JsonResponse
*
* @throws \Exception
*/
protected function updateGridConfigShares(?GridConfig $gridConfig, array $metadata)
protected function updateGridConfigShares(?GridConfig $gridConfig, array $metadata): void
{
$user = $this->getAdminUser();
if (!$gridConfig || !$user->isAllowed('share_configurations')) {
Expand Down Expand Up @@ -614,7 +614,7 @@ protected function updateGridConfigShares(?GridConfig $gridConfig, array $metada
*
* @throws \Exception
*/
protected function updateGridConfigFavourites(?GridConfig $gridConfig, array $metadata)
protected function updateGridConfigFavourites(?GridConfig $gridConfig, array $metadata): void
{
$currentUser = $this->getAdminUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ public function doBulkExportAction(Request $request): Response
return $response;
}

public function onKernelControllerEvent(ControllerEvent $event)
public function onKernelControllerEvent(ControllerEvent $event): void
{
if (!$event->isMainRequest()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ public function getPageAction(Request $request): JsonResponse
return $this->adminJson(['success' => true, 'page' => $page]);
}

public function onKernelControllerEvent(ControllerEvent $event)
public function onKernelControllerEvent(ControllerEvent $event): void
{
if (!$event->isMainRequest()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ private function executeInsideTransaction(callable $fn): void
}
}

protected function reindexBasedOnSortOrder(DataObject\AbstractObject $parentObject, string $currentSortOrder)
protected function reindexBasedOnSortOrder(DataObject\AbstractObject $parentObject, string $currentSortOrder): void
{
$fn = function () use ($parentObject, $currentSortOrder) {
$list = new DataObject\Listing();
Expand Down Expand Up @@ -1703,7 +1703,7 @@ public function saveFolderAction(Request $request): JsonResponse
throw $this->createAccessDeniedHttpException();
}

protected function assignPropertiesFromEditmode(Request $request, DataObject\AbstractObject $object)
protected function assignPropertiesFromEditmode(Request $request, DataObject\AbstractObject $object): void
{
if ($request->get('properties')) {
$properties = [];
Expand Down Expand Up @@ -2159,7 +2159,7 @@ public function previewAction(Request $request): RedirectResponse|Response
}
}

protected function processRemoteOwnerRelations(DataObject\Concrete $object, array $toDelete, array $toAdd, string $ownerFieldName)
protected function processRemoteOwnerRelations(DataObject\Concrete $object, array $toDelete, array $toAdd, string $ownerFieldName): void
{
$getter = 'get' . ucfirst($ownerFieldName);
$setter = 'set' . ucfirst($ownerFieldName);
Expand Down Expand Up @@ -2241,7 +2241,7 @@ protected function detectAddedRemoteOwnerRelations(array $relations, array $valu
return $diff;
}

protected function getLatestVersion(DataObject\Concrete $object, &$draftVersion = null): DataObject\Concrete
protected function getLatestVersion(DataObject\Concrete $object, ?DataObject\Concrete &$draftVersion = null): DataObject\Concrete
{
$latestVersion = $object->getLatestVersion($this->getAdminUser()->getId());
if ($latestVersion) {
Expand All @@ -2256,7 +2256,7 @@ protected function getLatestVersion(DataObject\Concrete $object, &$draftVersion
return $object;
}

public function onKernelControllerEvent(ControllerEvent $event)
public function onKernelControllerEvent(ControllerEvent $event): void
{
if (!$event->isMainRequest()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public function getDefaultGridFields(bool $noSystemColumns, ?DataObject\ClassDef
* @param int $objectId
* @param array|null $context
*/
protected function appendBrickFields(DataObject\ClassDefinition\Data $field, array $brickFields, array &$availableFields, string $gridType, int &$count, string $brickType, DataObject\ClassDefinition $class, int $objectId, array $context = null)
protected function appendBrickFields(DataObject\ClassDefinition\Data $field, array $brickFields, array &$availableFields, string $gridType, int &$count, string $brickType, DataObject\ClassDefinition $class, int $objectId, array $context = null): void
{
if (!empty($brickFields)) {
foreach ($brickFields as $bf) {
Expand Down Expand Up @@ -970,7 +970,7 @@ public function gridSaveColumnConfigAction(Request $request): JsonResponse
*
* @throws \Exception
*/
protected function updateGridConfigShares(?GridConfig $gridConfig, array $metadata)
protected function updateGridConfigShares(?GridConfig $gridConfig, array $metadata): void
{
$user = $this->getAdminUser();
if (!$gridConfig || !$user->isAllowed('share_configurations')) {
Expand Down Expand Up @@ -1012,7 +1012,7 @@ protected function updateGridConfigShares(?GridConfig $gridConfig, array $metada
*
* @throws \Exception
*/
protected function updateGridConfigFavourites(?GridConfig $gridConfig, array $metadata, int $objectId)
protected function updateGridConfigFavourites(?GridConfig $gridConfig, array $metadata, int $objectId): void
{
$currentUser = $this->getAdminUser();

Expand Down Expand Up @@ -1220,36 +1220,6 @@ public function importUploadAction(Request $request): JsonResponse
return $response;
}

private function getDataPreview($originalFile, $dialect): array
{
$count = 0;
$data = [];
if (($handle = fopen($originalFile, 'r')) !== false) {
while (($rowData = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar)) !== false) {
$tmpData = [];

foreach ($rowData as $key => $value) {
$tmpData['field_' . $key] = $value;
}

$tmpData['rowId'] = $count + 1;
$data[] = $tmpData;

$count++;

/**
* Reached the number or rows for the preview
*/
if ($count > 18) {
break;
}
}
fclose($handle);
}

return $data;
}

protected function extractLanguage(Request $request): string
{
$requestedLanguage = $request->get('language');
Expand Down Expand Up @@ -1808,7 +1778,7 @@ public function getAvailableVisibleFieldsAction(Request $request): JsonResponse
* @param bool $firstOne
* @param DataObject\ClassDefinition\Data[] $commonFields
*/
protected function processAvailableFieldDefinitions(array $fds, bool &$firstOne, array &$commonFields)
protected function processAvailableFieldDefinitions(array $fds, bool &$firstOne, array &$commonFields): void
{
foreach ($fds as $fd) {
if ($fd instanceof DataObject\ClassDefinition\Data\Fieldcollections || $fd instanceof DataObject\ClassDefinition\Data\Objectbricks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ private function getSeoNodeConfig(Document $document): array
return $nodeConfig;
}

public function onKernelControllerEvent(ControllerEvent $event)
public function onKernelControllerEvent(ControllerEvent $event): void
{
if (!$event->isMainRequest()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function preSendDataActions(array &$data, Model\Document $document, ?V
throw $this->createAccessDeniedHttpException();
}

protected function addPropertiesToDocument(Request $request, Model\Document $document)
protected function addPropertiesToDocument(Request $request, Model\Document $document): void
{
// properties
if ($request->get('properties')) {
Expand Down Expand Up @@ -339,9 +339,9 @@ public function onKernelControllerEvent(ControllerEvent $event): void
$this->checkPermission('documents');
}

abstract protected function setValuesToDocument(Request $request, Model\Document $page);
abstract protected function setValuesToDocument(Request $request, Model\Document $document): void;

protected function handleTask(string $task, Model\Document\PageSnippet $page)
protected function handleTask(string $task, Model\Document\PageSnippet $page): void
{
if ($task === self::TASK_PUBLISH || $task === self::TASK_VERSION) {
$page->deleteAutoSaveVersions($this->getAdminUser()->getId());
Expand All @@ -368,7 +368,7 @@ protected function checkForLock(Model\Document $document): JsonResponse|bool
* @throws Element\ValidationException
* @throws \Exception
*/
protected function saveDocument(Model\Document $document, Request $request, bool $latestVersion = false, $task = null): array
protected function saveDocument(Model\Document $document, Request $request, bool $latestVersion = false, ?string $task = null): array
{
if ($latestVersion && $document instanceof Model\Document\PageSnippet) {
$document = $this->getLatestVersion($document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public function saveAction(Request $request): JsonResponse
}
}

protected function setValuesToDocument(Request $request, Document $page): void
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);
$this->applySchedulerDataToElement($request, $page);
$this->addSettingsToDocument($request, $document);
$this->addDataToDocument($request, $document);
$this->addPropertiesToDocument($request, $document);
$this->applySchedulerDataToElement($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function saveAction(Request $request): JsonResponse
return $this->adminJson(['success' => true, 'treeData' => $treeData]);
}

protected function setValuesToDocument(Request $request, Document $folder)
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addPropertiesToDocument($request, $folder);
$this->addPropertiesToDocument($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function saveAction(Request $request): JsonResponse

/**
* @param Request $request
* @param Document\Hardlink $link
* @param Document\Hardlink $document
*/
protected function setValuesToDocument(Request $request, Document $link)
protected function setValuesToDocument(Request $request, Document $document): void
{
// data
if ($request->get('data')) {
Expand All @@ -118,11 +118,11 @@ protected function setValuesToDocument(Request $request, Document $link)
if ($sourceDocument = Document::getByPath($data['sourcePath'])) {
$sourceId = $sourceDocument->getId();
}
$link->setSourceId($sourceId);
$link->setValues($data);
$document->setSourceId($sourceId);
$document->setValues($data);
}

$this->addPropertiesToDocument($request, $link);
$this->applySchedulerDataToElement($request, $link);
$this->addPropertiesToDocument($request, $document);
$this->applySchedulerDataToElement($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public function saveAction(Request $request): JsonResponse

/**
* @param Request $request
* @param Document\Link $link
* @param Document\Link $document
*/
protected function setValuesToDocument(Request $request, Document $link)
protected function setValuesToDocument(Request $request, Document $document): void
{
// data
if ($request->get('data')) {
Expand Down Expand Up @@ -163,10 +163,10 @@ protected function setValuesToDocument(Request $request, Document $link)

unset($data['path']);

$link->setValues($data);
$document->setValues($data);
}

$this->addPropertiesToDocument($request, $link);
$this->applySchedulerDataToElement($request, $link);
$this->addPropertiesToDocument($request, $document);
$this->applySchedulerDataToElement($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ public function saveAction(Request $request): JsonResponse
}
}

protected function setValuesToDocument(Request $request, Document $page)
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);
$this->addSettingsToDocument($request, $document);
$this->addDataToDocument($request, $document);
$this->addPropertiesToDocument($request, $document);

// plaintext
if ($request->get('plaintext')) {
$plaintext = $this->decodeJson($request->get('plaintext'));
$page->setValues($plaintext);
$document->setValues($plaintext);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ public function areabrickRenderIndexEditmode(
]);
}

protected function setValuesToDocument(Request $request, Document $page)
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);
$this->applySchedulerDataToElement($request, $page);
$this->addSettingsToDocument($request, $document);
$this->addDataToDocument($request, $document);
$this->addPropertiesToDocument($request, $document);
$this->applySchedulerDataToElement($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public function saveAction(Request $request): JsonResponse
}
}

protected function setValuesToDocument(Request $request, Document $page): void
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);
$this->addSettingsToDocument($request, $document);
$this->addDataToDocument($request, $document);
$this->addPropertiesToDocument($request, $document);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public function saveAction(Request $request): JsonResponse
}
}

protected function setValuesToDocument(Request $request, Document $snippet)
protected function setValuesToDocument(Request $request, Document $document): void
{
$this->addSettingsToDocument($request, $snippet);
$this->addDataToDocument($request, $snippet);
$this->applySchedulerDataToElement($request, $snippet);
$this->addPropertiesToDocument($request, $snippet);
$this->addSettingsToDocument($request, $document);
$this->addDataToDocument($request, $document);
$this->applySchedulerDataToElement($request, $document);
$this->addPropertiesToDocument($request, $document);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ public function analyzePermissionsAction(Request $request): Response
{
$userId = $request->request->getInt('userId');
if ($userId) {
$user = Model\User::getById($userId);
$userList = [$user];
$userList = [];
if ($user = Model\User::getById($userId)) {
$userList[] = $user;
}
} else {
$userList = new Model\User\Listing();
$userList->setCondition('`type` = ?', ['user']);
Expand Down
Loading

0 comments on commit bbcc422

Please sign in to comment.