Skip to content

Commit e9dd16a

Browse files
committed
Add typehints and return types
1 parent a0275d3 commit e9dd16a

File tree

98 files changed

+712
-1934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+712
-1934
lines changed

src/Admin/BaseBlockAdmin.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@
3131
*/
3232
abstract class BaseBlockAdmin extends AbstractAdmin
3333
{
34-
/**
35-
* @var BlockServiceManagerInterface
36-
*/
37-
protected $blockManager;
34+
protected BlockServiceManagerInterface $blockManager;
3835

39-
/**
40-
* @var bool
41-
*/
42-
protected $inValidate = false;
36+
protected bool $inValidate = false;
4337

4438
/**
4539
* @var array<string>
4640
*/
47-
protected $containerBlockTypes = [];
41+
protected array $containerBlockTypes = [];
4842

4943
public function __construct(BlockServiceManagerInterface $blockManager)
5044
{

src/Admin/PageAdmin.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ protected function configureRoutes(RouteCollectionInterface $collection): void
7272
$collection->add('tree', 'tree');
7373
}
7474

75-
protected function preUpdate($object): void
75+
protected function preUpdate(object $object): void
7676
{
7777
$object->setEdited(true);
7878
}
7979

80-
protected function prePersist($object): void
80+
protected function prePersist(object $object): void
8181
{
8282
$object->setEdited(true);
8383
}
@@ -392,10 +392,8 @@ protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminI
392392

393393
/**
394394
* @throws \RuntimeException
395-
*
396-
* @return SiteInterface|null
397395
*/
398-
private function getSite()
396+
private function getSite(): ?SiteInterface
399397
{
400398
if (!$this->hasRequest()) {
401399
return null;

src/Block/BreadcrumbBlockService.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,12 @@ protected function getMenu(BlockContextInterface $blockContext): ItemInterface
8181
return $menu;
8282
}
8383

84-
/**
85-
* @return string
86-
*/
87-
private function getName()
84+
private function getName(): string
8885
{
8986
return 'sonata.page.block.breadcrumb';
9087
}
9188

92-
/**
93-
* @return PageInterface|null
94-
*/
95-
private function getCurrentPage()
89+
private function getCurrentPage(): ?PageInterface
9690
{
9791
$cms = $this->cmsSelector->retrieve();
9892

src/CmsManager/BaseCmsPageManager.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@
2222
*/
2323
abstract class BaseCmsPageManager implements CmsManagerInterface
2424
{
25-
/**
26-
* @var PageInterface|null
27-
*/
28-
protected $currentPage = null;
25+
protected ?PageInterface $currentPage = null;
2926

3027
/**
3128
* @var array<PageBlockInterface|null>
3229
*/
33-
protected $blocks = [];
30+
protected array $blocks = [];
3431

35-
public function getCurrentPage()
32+
public function getCurrentPage(): ?PageInterface
3633
{
3734
return $this->currentPage;
3835
}
@@ -42,43 +39,40 @@ public function setCurrentPage(PageInterface $page): void
4239
$this->currentPage = $page;
4340
}
4441

45-
public function getBlocks()
42+
public function getBlocks(): array
4643
{
4744
return $this->blocks;
4845
}
4946

50-
public function getPageByUrl(SiteInterface $site, $slug): PageInterface
47+
public function getPageByUrl(SiteInterface $site, string $slug): PageInterface
5148
{
5249
return $this->getPageBy($site, 'url', $slug);
5350
}
5451

55-
public function getPageByRouteName(SiteInterface $site, $routeName)
52+
public function getPageByRouteName(SiteInterface $site, string $routeName): PageInterface
5653
{
5754
return $this->getPageBy($site, 'routeName', $routeName);
5855
}
5956

60-
public function getPageByPageAlias(SiteInterface $site, $pageAlias)
57+
public function getPageByPageAlias(SiteInterface $site, string $pageAlias): PageInterface
6158
{
6259
return $this->getPageBy($site, 'pageAlias', $pageAlias);
6360
}
6461

65-
public function getPageByName(SiteInterface $site, $name)
62+
public function getPageByName(SiteInterface $site, string $name): PageInterface
6663
{
6764
return $this->getPageBy($site, 'name', $name);
6865
}
6966

70-
public function getPageById($id)
67+
public function getPageById($id): PageInterface
7168
{
7269
return $this->getPageBy(null, 'id', $id);
7370
}
7471

7572
/**
76-
* @param string $fieldName
7773
* @param int|string $value
7874
*
79-
* @return PageInterface
80-
*
8175
* @phpstan-param 'id'|'url'|'routeName'|'pageAlias'|'name' $fieldName
8276
*/
83-
abstract protected function getPageBy(?SiteInterface $site, $fieldName, $value);
77+
abstract protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface;
8478
}

src/CmsManager/CmsManagerInterface.php

+12-52
Original file line numberDiff line numberDiff line change
@@ -25,79 +25,39 @@
2525
*/
2626
interface CmsManagerInterface
2727
{
28-
/**
29-
* @param string $name
30-
*
31-
* @return PageBlockInterface|null
32-
*/
33-
public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null);
28+
public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface;
3429

35-
/**
36-
* @param string $slug
37-
*/
38-
public function getPageByUrl(SiteInterface $site, $slug): PageInterface;
30+
public function getPageByUrl(SiteInterface $site, string $slug): PageInterface;
3931

40-
/**
41-
* @param string $routeName
42-
*
43-
* @return PageInterface
44-
*/
45-
public function getPageByRouteName(SiteInterface $site, $routeName);
32+
public function getPageByRouteName(SiteInterface $site, string $routeName): PageInterface;
4633

47-
/**
48-
* @param string $pageAlias
49-
*
50-
* @return PageInterface
51-
*/
52-
public function getPageByPageAlias(SiteInterface $site, $pageAlias);
34+
public function getPageByPageAlias(SiteInterface $site, string $pageAlias): PageInterface;
5335

54-
/**
55-
* @param string $routeName
56-
*
57-
* @return PageInterface
58-
*/
59-
public function getInternalRoute(SiteInterface $site, $routeName);
36+
public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface;
6037

61-
/**
62-
* @param string $name
63-
*
64-
* @return PageInterface
65-
*/
66-
public function getPageByName(SiteInterface $site, $name);
38+
public function getPageByName(SiteInterface $site, string $name): PageInterface;
6739

6840
/**
6941
* @param int|string $id
70-
*
71-
* @return PageInterface
7242
*/
73-
public function getPageById($id);
43+
public function getPageById($id): PageInterface;
7444

7545
/**
7646
* @param int|string $id
77-
*
78-
* @return PageBlockInterface|null
7947
*/
80-
public function getBlock($id);
48+
public function getBlock($id): ?PageBlockInterface;
8149

82-
/**
83-
* @return PageInterface|null
84-
*/
85-
public function getCurrentPage();
50+
public function getCurrentPage(): ?PageInterface;
8651

87-
/**
88-
* @return void
89-
*/
90-
public function setCurrentPage(PageInterface $page);
52+
public function setCurrentPage(PageInterface $page): void;
9153

9254
/**
9355
* @return array<PageBlockInterface|null>
9456
*/
95-
public function getBlocks();
57+
public function getBlocks(): array;
9658

9759
/**
9860
* @param int|string|null $page
99-
*
100-
* @return PageInterface
10161
*/
102-
public function getPage(SiteInterface $site, $page);
62+
public function getPage(SiteInterface $site, $page): PageInterface;
10363
}

src/CmsManager/CmsManagerSelector.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
final class CmsManagerSelector implements CmsManagerSelectorInterface, BCLogoutHandlerInterface
3434
{
3535
private CmsPageManager $cmsPageManager;
36+
3637
private CmsSnapshotManager $cmsSnapshotManager;
3738

3839
/**
@@ -41,6 +42,7 @@ final class CmsManagerSelector implements CmsManagerSelectorInterface, BCLogoutH
4142
private AdminInterface $pageAdmin;
4243

4344
private TokenStorageInterface $tokenStorage;
45+
4446
private RequestStack $requestStack;
4547

4648
/**
@@ -60,7 +62,7 @@ public function __construct(
6062
$this->requestStack = $requestStack;
6163
}
6264

63-
public function retrieve()
65+
public function retrieve(): CmsManagerInterface
6466
{
6567
return $this->isEditor() ? $this->cmsPageManager : $this->cmsSnapshotManager;
6668
}
@@ -70,7 +72,7 @@ public function retrieve()
7072
* by the router chain, so we need to use another mechanism. It is not perfect
7173
* but do the job for now.
7274
*/
73-
public function isEditor()
75+
public function isEditor(): bool
7476
{
7577
$request = $this->requestStack->getCurrentRequest();
7678

src/CmsManager/CmsManagerSelectorInterface.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
*/
1919
interface CmsManagerSelectorInterface
2020
{
21-
/**
22-
* @return CmsManagerInterface
23-
*/
24-
public function retrieve();
21+
public function retrieve(): CmsManagerInterface;
2522

26-
/**
27-
* @return bool
28-
*/
29-
public function isEditor();
23+
public function isEditor(): bool;
3024
}

src/CmsManager/CmsPageManager.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class CmsPageManager extends BaseCmsPageManager
4545
];
4646

4747
/**
48-
* @var PageInterface[]
48+
* @var array<PageInterface>
4949
*/
5050
private array $pages = [];
5151

@@ -55,7 +55,7 @@ public function __construct(PageManagerInterface $pageManager, BlockInteractorIn
5555
$this->blockInteractor = $blockInteractor;
5656
}
5757

58-
public function getPage(SiteInterface $site, $page)
58+
public function getPage(SiteInterface $site, $page): PageInterface
5959
{
6060
if (\is_string($page) && '/' === substr($page, 0, 1)) {
6161
$page = $this->getPageByUrl($site, $page);
@@ -74,7 +74,7 @@ public function getPage(SiteInterface $site, $page)
7474
return $page;
7575
}
7676

77-
public function getInternalRoute(SiteInterface $site, $routeName)
77+
public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface
7878
{
7979
if ('error' === substr($routeName, 0, 5)) {
8080
throw new \RuntimeException(sprintf('Illegal internal route name : %s, an internal page cannot start with `error`', $routeName));
@@ -100,7 +100,7 @@ public function getInternalRoute(SiteInterface $site, $routeName)
100100
return $page;
101101
}
102102

103-
public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null)
103+
public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface
104104
{
105105
$container = null;
106106

@@ -134,7 +134,7 @@ public function findContainer($name, PageInterface $page, ?PageBlockInterface $p
134134
return $container;
135135
}
136136

137-
public function getBlock($id)
137+
public function getBlock($id): ?PageBlockInterface
138138
{
139139
if (!\array_key_exists($id, $this->blocks)) {
140140
$this->blocks[$id] = $this->blockInteractor->getBlock($id);
@@ -143,7 +143,7 @@ public function getBlock($id)
143143
return $this->blocks[$id];
144144
}
145145

146-
protected function getPageBy(?SiteInterface $site, $fieldName, $value)
146+
protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface
147147
{
148148
if ('id' === $fieldName) {
149149
$id = $value;

src/CmsManager/CmsSnapshotManager.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(SnapshotManagerInterface $snapshotManager, Transform
5858
$this->transformer = $transformer;
5959
}
6060

61-
public function getPage(SiteInterface $site, $page)
61+
public function getPage(SiteInterface $site, $page): PageInterface
6262
{
6363
if (\is_string($page) && '/' === substr($page, 0, 1)) {
6464
$page = $this->getPageByUrl($site, $page);
@@ -77,12 +77,12 @@ public function getPage(SiteInterface $site, $page)
7777
return $page;
7878
}
7979

80-
public function getInternalRoute(SiteInterface $site, $routeName)
80+
public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface
8181
{
8282
return $this->getPageByRouteName($site, sprintf('_page_internal_%s', $routeName));
8383
}
8484

85-
public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null)
85+
public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface
8686
{
8787
$container = null;
8888

@@ -106,7 +106,7 @@ public function findContainer($name, PageInterface $page, ?PageBlockInterface $p
106106
return $container;
107107
}
108108

109-
public function getBlock($id)
109+
public function getBlock($id): ?PageBlockInterface
110110
{
111111
if (isset($this->blocks[$id])) {
112112
return $this->blocks[$id];
@@ -115,7 +115,7 @@ public function getBlock($id)
115115
return null;
116116
}
117117

118-
protected function getPageBy(?SiteInterface $site, $fieldName, $value)
118+
protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface
119119
{
120120
if ('id' === $fieldName) {
121121
$fieldName = 'pageId';

0 commit comments

Comments
 (0)