Skip to content

Commit 0790a51

Browse files
Move from protected to private when possible (#1510)
1 parent 22beb84 commit 0790a51

32 files changed

+105
-140
lines changed

src/Admin/BlockAdmin.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
*/
3535
final class BlockAdmin extends BaseBlockAdmin
3636
{
37-
protected array $blocks;
38-
3937
protected $classnameLabel = 'Block';
38+
private array $blocks;
4039

4140
public function __construct(array $blocks = [])
4241
{

src/Admin/Extension/CreateSnapshotAdminExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
final class CreateSnapshotAdminExtension extends AbstractAdminExtension
2626
{
27-
protected CreateSnapshotByPageInterface $createSnapshotByPage;
27+
private CreateSnapshotByPageInterface $createSnapshotByPage;
2828

2929
public function __construct(CreateSnapshotByPageInterface $createSnapshotByPage)
3030
{

src/Admin/PageAdmin.php

+48-56
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ final class PageAdmin extends AbstractAdmin
4545
{
4646
protected $classnameLabel = 'Page';
4747

48-
protected ?PageManagerInterface $pageManager = null;
48+
private ?PageManagerInterface $pageManager = null;
4949

50-
protected ?SiteManagerInterface $siteManager = null;
50+
private ?SiteManagerInterface $siteManager = null;
5151

52-
public function configureRoutes(RouteCollectionInterface $collection): void
52+
public function setPageManager(PageManagerInterface $pageManager): void
53+
{
54+
$this->pageManager = $pageManager;
55+
}
56+
57+
public function setSiteManager(SiteManagerInterface $siteManager): void
58+
{
59+
$this->siteManager = $siteManager;
60+
}
61+
62+
protected function configureRoutes(RouteCollectionInterface $collection): void
5363
{
5464
$collection->add('compose', '{id}/compose', [
5565
'id' => null,
@@ -61,67 +71,16 @@ public function configureRoutes(RouteCollectionInterface $collection): void
6171
$collection->add('tree', 'tree');
6272
}
6373

64-
public function preUpdate($object): void
74+
protected function preUpdate($object): void
6575
{
6676
$object->setEdited(true);
6777
}
6878

69-
public function prePersist($object): void
79+
protected function prePersist($object): void
7080
{
7181
$object->setEdited(true);
7282
}
7383

74-
public function setPageManager(PageManagerInterface $pageManager): void
75-
{
76-
$this->pageManager = $pageManager;
77-
}
78-
79-
/**
80-
* @throws \RuntimeException
81-
*
82-
* @return SiteInterface|bool
83-
*/
84-
public function getSite()
85-
{
86-
if (!$this->hasRequest()) {
87-
return false;
88-
}
89-
90-
$siteId = null;
91-
92-
if ('POST' === $this->getRequest()->getMethod()) {
93-
$values = $this->getRequest()->get($this->getUniqid());
94-
$siteId = $values['site'] ?? null;
95-
}
96-
97-
$siteId ??= $this->getRequest()->get('siteId');
98-
99-
if ($siteId) {
100-
$site = $this->siteManager->findOneBy(['id' => $siteId]);
101-
102-
if (!$site) {
103-
throw new \RuntimeException('Unable to find the site with id='.$this->getRequest()->get('siteId'));
104-
}
105-
106-
return $site;
107-
}
108-
109-
return false;
110-
}
111-
112-
public function setSiteManager(SiteManagerInterface $siteManager): void
113-
{
114-
$this->siteManager = $siteManager;
115-
}
116-
117-
/**
118-
* @return SiteInterface[]
119-
*/
120-
public function getSites()
121-
{
122-
return $this->siteManager->findBy([]);
123-
}
124-
12584
protected function getAccessMapping(): array
12685
{
12786
return [
@@ -417,4 +376,37 @@ protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminI
417376
}
418377
}
419378
}
379+
380+
/**
381+
* @throws \RuntimeException
382+
*
383+
* @return SiteInterface|bool
384+
*/
385+
private function getSite()
386+
{
387+
if (!$this->hasRequest()) {
388+
return false;
389+
}
390+
391+
$siteId = null;
392+
393+
if ('POST' === $this->getRequest()->getMethod()) {
394+
$values = $this->getRequest()->get($this->getUniqid());
395+
$siteId = $values['site'] ?? null;
396+
}
397+
398+
$siteId ??= $this->getRequest()->get('siteId');
399+
400+
if ($siteId) {
401+
$site = $this->siteManager->findOneBy(['id' => $siteId]);
402+
403+
if (!$site) {
404+
throw new \RuntimeException('Unable to find the site with id='.$this->getRequest()->get('siteId'));
405+
}
406+
407+
return $site;
408+
}
409+
410+
return false;
411+
}
420412
}

src/Admin/SiteAdmin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class SiteAdmin extends AbstractAdmin
3434
{
3535
protected $classnameLabel = 'Site';
3636

37-
protected RoutePageGenerator $routePageGenerator;
37+
private RoutePageGenerator $routePageGenerator;
3838

3939
public function __construct(RoutePageGenerator $routePageGenerator)
4040
{

src/Block/SharedBlockBlockService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function preUpdate(BlockInterface $block): void
136136
$block->setSetting('blockId', \is_object($block->getSetting('blockId')) ? $block->getSetting('blockId')->getId() : null);
137137
}
138138

139-
protected function getBlockBuilder(): FormBuilderInterface
139+
private function getBlockBuilder(): FormBuilderInterface
140140
{
141141
$fieldDescription = $this->sharedBlockAdmin->createFieldDescription('block', [
142142
'translation_domain' => 'SonataPageBundle',

src/CmsManager/CmsPageManager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
*/
2828
final class CmsPageManager extends BaseCmsPageManager
2929
{
30-
protected BlockInteractorInterface $blockInteractor;
30+
private BlockInteractorInterface $blockInteractor;
3131

32-
protected PageManagerInterface $pageManager;
32+
private PageManagerInterface $pageManager;
3333

34-
protected array $pageReferences = [];
34+
private array $pageReferences = [];
3535

3636
/**
3737
* @var PageInterface[]
3838
*/
39-
protected array $pages = [];
39+
private array $pages = [];
4040

4141
public function __construct(PageManagerInterface $pageManager, BlockInteractorInterface $blockInteractor)
4242
{

src/CmsManager/CmsSnapshotManager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
*/
2929
final class CmsSnapshotManager extends BaseCmsPageManager
3030
{
31-
protected SnapshotManagerInterface $snapshotManager;
31+
private SnapshotManagerInterface $snapshotManager;
3232

33-
protected TransformerInterface $transformer;
33+
private TransformerInterface $transformer;
3434

35-
protected array $pageReferences = [];
35+
private array $pageReferences = [];
3636

3737
/**
3838
* @var PageInterface[]
3939
*/
40-
protected array $pages = [];
40+
private array $pages = [];
4141

4242
public function __construct(SnapshotManagerInterface $snapshotManager, TransformerInterface $transformer)
4343
{

src/Entity/PageManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
*/
3030
final class PageManager extends BaseEntityManager implements PageManagerInterface
3131
{
32-
protected array $pageDefaults;
32+
private array $pageDefaults;
3333

34-
protected array $defaults;
34+
private array $defaults;
3535

3636
/**
3737
* @param string $class

src/Entity/SnapshotManager.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
*/
3333
final class SnapshotManager extends BaseEntityManager implements SnapshotManagerInterface
3434
{
35-
protected array $children = [];
36-
37-
protected SnapshotPageProxyFactoryInterface $snapshotPageProxyFactory;
35+
private SnapshotPageProxyFactoryInterface $snapshotPageProxyFactory;
3836

3937
/**
4038
* @param string $class Namespace of entity class

src/Form/Type/PageSelectorType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
final class PageSelectorType extends AbstractType
3030
{
31-
protected PageManagerInterface $manager;
31+
private PageManagerInterface $manager;
3232

3333
public function __construct(PageManagerInterface $manager)
3434
{

src/Form/Type/PageTypeChoiceType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class PageTypeChoiceType extends AbstractType
2727
{
28-
protected PageServiceManagerInterface $manager;
28+
private PageServiceManagerInterface $manager;
2929

3030
public function __construct(PageServiceManagerInterface $manager)
3131
{

src/Form/Type/TemplateChoiceType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class TemplateChoiceType extends AbstractType
2727
{
28-
protected TemplateManagerInterface $manager;
28+
private TemplateManagerInterface $manager;
2929

3030
public function __construct(TemplateManagerInterface $manager)
3131
{

src/Page/Service/DefaultPageService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
*/
2929
final class DefaultPageService extends BasePageService
3030
{
31-
protected TemplateManagerInterface $templateManager;
31+
private TemplateManagerInterface $templateManager;
3232

33-
protected ?SeoPageInterface $seoPage;
33+
private ?SeoPageInterface $seoPage;
3434

3535
/**
3636
* @param string $name Page service name
@@ -55,7 +55,7 @@ public function execute(PageInterface $page, Request $request, array $parameters
5555
/**
5656
* Updates the SEO page values for given page instance.
5757
*/
58-
protected function updateSeoPage(PageInterface $page): void
58+
private function updateSeoPage(PageInterface $page): void
5959
{
6060
if (!$this->seoPage) {
6161
return;

src/Request/SiteRequestContext.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
final class SiteRequestContext extends RequestContext implements SiteRequestContextInterface
2424
{
25-
protected SiteSelectorInterface $selector;
25+
private SiteSelectorInterface $selector;
2626

2727
private ?SiteInterface $site = null;
2828

src/Validator/UniqueUrlValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
final class UniqueUrlValidator extends ConstraintValidator
2525
{
26-
protected PageManagerInterface $manager;
26+
private PageManagerInterface $manager;
2727

2828
public function __construct(PageManagerInterface $manager)
2929
{

tests/Block/PageListBlockServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class PageListBlockServiceTest extends BlockServiceTestCase
2929
/**
3030
* @var PageManagerInterface&MockObject
3131
*/
32-
protected $pageManager;
32+
private $pageManager;
3333

3434
protected function setUp(): void
3535
{

tests/CmsManager/CmsPageManagerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function testGetPageWithoutParamException(): void
269269
*
270270
* @return MockObject&BlockInteractorInterface
271271
*/
272-
protected function getMockBlockInteractor(): BlockInteractorInterface
272+
private function getMockBlockInteractor(): BlockInteractorInterface
273273
{
274274
$callback = static function ($options) {
275275
$block = new CmsBlock();

tests/CmsManager/CmsSnapshotManagerTest.php

+3-27
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Sonata\PageBundle\CmsManager\CmsSnapshotManager;
1818
use Sonata\PageBundle\Exception\PageNotFoundException;
1919
use Sonata\PageBundle\Model\Block;
20-
use Sonata\PageBundle\Model\BlockInteractorInterface;
2120
use Sonata\PageBundle\Model\PageBlockInterface;
2221
use Sonata\PageBundle\Model\SiteInterface;
2322
use Sonata\PageBundle\Model\SnapshotInterface;
@@ -44,20 +43,17 @@ public function getId()
4443

4544
final class CmsSnapshotManagerTest extends TestCase
4645
{
47-
protected CmsSnapshotManager $manager;
46+
private CmsSnapshotManager $manager;
4847

49-
protected $blockInteractor;
48+
private $snapshotManager;
5049

51-
protected $snapshotManager;
52-
53-
protected $transformer;
50+
private $transformer;
5451

5552
/**
5653
* Setup manager object to test.
5754
*/
5855
protected function setUp(): void
5956
{
60-
$this->blockInteractor = $this->getMockBlockInteractor();
6157
$this->snapshotManager = $this->createMock(SnapshotManagerInterface::class);
6258
$this->transformer = $this->createMock(TransformerInterface::class);
6359
$this->manager = new CmsSnapshotManager($this->snapshotManager, $this->transformer);
@@ -139,24 +135,4 @@ public function testGetPageWithId(): void
139135
static::assertInstanceOf(PageBlockInterface::class, $this->manager->getBlock(1));
140136
static::assertInstanceOf(PageBlockInterface::class, $this->manager->getBlock(2));
141137
}
142-
143-
/**
144-
* Returns a mock block interactor.
145-
*/
146-
protected function getMockBlockInteractor(): BlockInteractorInterface
147-
{
148-
$callback = static function ($options) {
149-
$block = new SnapshotBlock();
150-
$block->setSettings($options);
151-
152-
return $block;
153-
};
154-
155-
$blockInteractor = $this->createMock(BlockInteractorInterface::class);
156-
$blockInteractor
157-
->method('createNewContainer')
158-
->willReturnCallback($callback);
159-
160-
return $blockInteractor;
161-
}
162138
}

tests/Entity/BlockInteractorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ final class BlockInteractorTest extends KernelTestCase
2626
/**
2727
* @var EntityManagerInterface
2828
*/
29-
protected $entityManager;
29+
private $entityManager;
3030

31-
protected BlockInteractor $blockInteractor;
31+
private BlockInteractor $blockInteractor;
3232

3333
protected function setUp(): void
3434
{

0 commit comments

Comments
 (0)