Skip to content

Commit

Permalink
Merge pull request PrestaShop#36021 from jolelievre/phpstan-doctrine
Browse files Browse the repository at this point in the history
Integrate phpstan extension for Doctrine
  • Loading branch information
jolelievre authored Apr 25, 2024
2 parents d07c120 + 4426ad7 commit 909ea5e
Show file tree
Hide file tree
Showing 26 changed files with 559 additions and 1,730 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"mikey179/vfsstream": "^1.6",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9.3",
"phpstan/phpstan-doctrine": "^1.3",
"phpunit/phpunit": "~9.6.7",
"rector/rector": "^0.15.17",
"spaze/phpstan-disallowed-calls": "^2.10",
Expand Down
72 changes: 71 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1449,3 +1449,8 @@ parameters:
message: "#^Namespace Currency is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#"
count: 1
path: src/PrestaShopBundle/Twig/LayoutExtension.php

-
message: "#^Parameter \\#1 \\$className of method Doctrine\\\\ORM\\\\EntityManagerInterface\\:\\:getClassMetadata\\(\\) expects class\\-string\\<\\\\PrestaShop\\\\Module\\\\Banner\\\\Entity\\\\Banner\\>, string given\\.$#"
count: 1
path: tests/Integration/Adapter/ContainerBuilderTest.php
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ parameters:
- '~^Access to an undefined property PrestaShop\\PrestaShop\\Core\\Module\\ModuleInterface::\$(attributes|disk|database)\.$~'
## Smarty functions
- '#^Function smartyRegisterFunction not found\.$#'
## Doctrine Entities
- '#Property PrestaShopBundle\\Entity\\[A-Za-z]+\:\:\$[A-Za-z]+ is never written, only read.#'
## CQRS API Platform operations
-
message: '#Constructor of class [a-zA-Z0-9\\_]+ has an unused parameter \$[a-zA-Z0-9_]+.$#'
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Shop/QueryHandler/SearchShopsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function handle(SearchShops $query): array
if (!$shopGroup->getShops()->isEmpty()) {
$result[] = new FoundShopGroup(
$shopGroup->getId(),
$shopGroup->getColor() ?? '',
$shopGroup->getColor(),
$shopGroup->getName()
);
}
Expand Down
150 changes: 25 additions & 125 deletions src/PrestaShopBundle/Entity/AdminFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,202 +38,115 @@
class AdminFilter
{
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private int $id;

/**
* @var int
*
* @ORM\Column(name="employee", type="integer")
*/
private $employee;
private int $employee;

/**
* @var int
*
* @ORM\Column(name="shop", type="integer")
*/
private $shop;
private int $shop;

/**
* @var string
*
* @ORM\Column(name="controller", type="string", length=60)
*/
private $controller;
private string $controller;

/**
* @var string
*
* @ORM\Column(name="action", type="string", length=100)
*/
private $action;
private string $action;

/**
* @var string
*
* @ORM\Column(name="filter", type="text")
*/
private $filter;
private string $filter;

/**
* @var string
*
* @ORM\Column(name="filter_id", type="string", length=191)
*/
private $filterId = '';
private string $filterId = '';

/**
* Get id.
*
* @return int
*/
public function getId()
public function getId(): int
{
return $this->id;
}

/**
* Set employee.
*
* @param int $employee
*
* @return AdminFilter
*/
public function setEmployee($employee)
public function setEmployee(int $employee): static
{
$this->employee = $employee;

return $this;
}

/**
* Get employee.
*
* @return int
*/
public function getEmployee()
public function getEmployee(): int
{
return $this->employee;
}

/**
* Set shop.
*
* @param int $shop
*
* @return AdminFilter
*/
public function setShop($shop)
public function setShop(int $shop): static
{
$this->shop = $shop;

return $this;
}

/**
* Get shop.
*
* @return int
*/
public function getShop()
public function getShop(): int
{
return $this->shop;
}

/**
* Set controller.
*
* @param string $controller
*
* @return AdminFilter
*/
public function setController($controller)
public function setController(string $controller): static
{
$this->controller = $controller;

return $this;
}

/**
* Get controller.
*
* @return string
*/
public function getController()
public function getController(): string
{
return $this->controller;
}

/**
* Set action.
*
* @param string $action
*
* @return AdminFilter
*/
public function setAction($action)
public function setAction(string $action): static
{
$this->action = $action;

return $this;
}

/**
* Get action.
*
* @return string
*/
public function getAction()
public function getAction(): string
{
return $this->action;
}

/**
* Set filter.
*
* @param string $filter
*
* @return AdminFilter
*/
public function setFilter($filter)
public function setFilter(string $filter): static
{
$this->filter = $filter;

return $this;
}

/**
* Get filter.
*
* @return string
*/
public function getFilter()
public function getFilter(): string
{
return $this->filter;
}

/**
* @return string
*/
public function getFilterId()
public function getFilterId(): string
{
return $this->filterId;
}

/**
* @param string $filterId
*
* @return AdminFilter
*/
public function setFilterId($filterId)
public function setFilterId(string $filterId): static
{
$this->filterId = $filterId;

Expand All @@ -244,10 +157,8 @@ public function setFilterId($filterId)
* Gets an array with each filter key needed by Product catalog page.
*
* Values are filled with empty strings.
*
* @return array
*/
public static function getProductCatalogEmptyFilter()
public static function getProductCatalogEmptyFilter(): array
{
return [
'filter_category' => '',
Expand All @@ -268,12 +179,9 @@ public static function getProductCatalogEmptyFilter()
/**
* Gets an array with filters needed by Product catalog page.
*
* The data is decoded and filled with empty strings if there is no value on each entry
* .
*
* @return array
* The data is decoded and filled with empty strings if there is no value on each entry.
*/
public function getProductCatalogFilter()
public function getProductCatalogFilter(): array
{
$decoded = json_decode($this->getFilter(), true);

Expand All @@ -287,12 +195,8 @@ public function getProductCatalogFilter()
* Set the filters for Product catalog page into $this->filter.
*
* Filters input data to keep only Product catalog filters, and encode it.
*
* @param array $filter
*
* @return AdminFilter tis object for fluent chaining
*/
public function setProductCatalogFilter($filter)
public function setProductCatalogFilter(array $filter): static
{
$filter = array_intersect_key(
$filter,
Expand All @@ -305,12 +209,8 @@ public function setProductCatalogFilter($filter)

/**
* Sanitize filter parameters.
*
* @param array $filter
*
* @return mixed
*/
public static function sanitizeFilterParameters(array $filter)
public static function sanitizeFilterParameters(array $filter): mixed
{
$filterMinMax = function ($filter) {
return function ($subject) use ($filter) {
Expand Down
Loading

0 comments on commit 909ea5e

Please sign in to comment.