Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 0ab409a

Browse files
authored
Merge pull request #105 from symfony-cmf/code-cleanup
visbility cleanup
2 parents 432eeda + f453964 commit 0ab409a

31 files changed

+585
-167
lines changed

UPGRADE-2.0.md

+8
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@
3838

3939
* The `subjectObject` and `translatedSubjectObject` with their related methods
4040
are renamed to `subject` and `translatedSubject`.
41+
42+
## Customization
43+
44+
A lot of previously protected fields and some methods where moved to private,
45+
as they are not meant to represent part of the contract. If you have a valid
46+
use case to extend one of the classes, please explain in a github issue and
47+
we will see whether that property should be made protected or whether ther is a
48+
cleaner sulution.

src/AutoRouteManager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ class AutoRouteManager
2323
/**
2424
* @var AdapterInterface
2525
*/
26-
protected $adapter;
26+
private $adapter;
2727

2828
/**
2929
* @var UriGeneratorInterface
3030
*/
31-
protected $uriGenerator;
31+
private $uriGenerator;
3232

3333
/**
3434
* @var DefunctRouteHandlerInterface
3535
*/
36-
protected $defunctRouteHandler;
36+
private $defunctRouteHandler;
3737

3838
/**
3939
* @var UriContextCollection[]
@@ -43,7 +43,7 @@ class AutoRouteManager
4343
/**
4444
* @var UriContextCollectionBuilder
4545
*/
46-
protected $collectionBuilder;
46+
private $collectionBuilder;
4747

4848
public function __construct(
4949
AdapterInterface $adapter,

src/ConflictResolver/AutoIncrementConflictResolver.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@
2424
*/
2525
class AutoIncrementConflictResolver implements ConflictResolverInterface
2626
{
27-
protected $adapter;
28-
protected $index;
27+
/**
28+
* @var AdapterInterface
29+
*/
30+
private $adapter;
31+
32+
/**
33+
* To count the increment, increased until conflic is resolved.
34+
*
35+
* @var int
36+
*/
37+
private $index;
2938

3039
/**
3140
* Construct the conflict resolver using the given adapter.
@@ -56,13 +65,13 @@ public function resolveConflict(UriContext $uriContext)
5665
* Tell if the given URI for the given context is conflicting with another
5766
* route.
5867
*/
59-
protected function isUriConflicting($uri, UriContext $uriContext)
68+
private function isUriConflicting($uri, UriContext $uriContext)
6069
{
6170
return null !== $uriContext->getCollection()->getAutoRouteByUri($uri)
6271
|| null !== $this->adapter->findRouteForUri($uri, $uriContext);
6372
}
6473

65-
protected function incrementUri($uri)
74+
private function incrementUri($uri)
6675
{
6776
return sprintf('%s-%s', $uri, ++$this->index);
6877
}

src/DefunctRouteHandler/DelegatingDefunctRouteHandler.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@
2525
*/
2626
class DelegatingDefunctRouteHandler implements DefunctRouteHandlerInterface
2727
{
28-
protected $serviceRegistry;
29-
protected $adapter;
28+
/**
29+
* Used to find the old route action.
30+
*
31+
* @var ServiceRegistry
32+
*/
33+
private $serviceRegistry;
34+
35+
/**
36+
* @var AdapterInterface
37+
*/
38+
private $adapter;
3039

3140
/**
32-
* @param ServiceRegistry auto routing service registry (for getting old route action)
33-
* @param AdapterInterface auto routing backend adapter
34-
* @param MetadataFactory auto routing metadata factory
41+
* @var MetadataFactory
3542
*/
43+
private $metadataFactory;
44+
3645
public function __construct(
3746
MetadataFactory $metadataFactory,
3847
AdapterInterface $adapter,

src/DefunctRouteHandler/LeaveRedirectDefunctRouteHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LeaveRedirectDefunctRouteHandler implements DefunctRouteHandlerInterface
2020
/**
2121
* @var AdapterInterface
2222
*/
23-
protected $adapter;
23+
private $adapter;
2424

2525
public function __construct(AdapterInterface $adapter)
2626
{

src/DefunctRouteHandler/RemoveDefunctRouteHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RemoveDefunctRouteHandler implements DefunctRouteHandlerInterface
2020
/**
2121
* @var AdapterInterface
2222
*/
23-
protected $adapter;
23+
private $adapter;
2424

2525
/**
2626
* @param AdapterInterface

src/Mapping/ClassMetadata.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class ClassMetadata extends MergeableClassMetadata
2424
/**
2525
* @var array
2626
*/
27-
protected $tokenProviders = [];
27+
private $tokenProviders = [];
2828

2929
/**
3030
* @var array
3131
*/
32-
protected $conflictResolver = ['name' => 'throw_exception', 'options' => []];
32+
private $conflictResolver = ['name' => 'throw_exception', 'options' => []];
3333

3434
/**
3535
* Defunct route handler, default to remove.

src/ServiceRegistry.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@
1313

1414
class ServiceRegistry
1515
{
16-
protected $tokenProviders = [];
17-
protected $conflictResolvers = [];
18-
protected $defunctRouteHandlers = [];
16+
/**
17+
* @var TokenProviderInterface[]
18+
*/
19+
private $tokenProviders = [];
20+
21+
/**
22+
* @var ConflictResolverInterface[]
23+
*/
24+
private $conflictResolvers = [];
25+
26+
/**
27+
* @var DefunctRouteHandlerInterface[]
28+
*/
29+
private $defunctRouteHandlers = [];
1930

2031
/**
2132
* Return the named token provider.
@@ -60,7 +71,7 @@ public function getConflictResolver($name)
6071
*
6172
* @throws \InvalidArgumentException if the named token provider does not exist
6273
*
63-
* @return ConflictResolverInterface
74+
* @return DefunctRouteHandlerInterface
6475
*/
6576
public function getDefunctRouteHandler($name)
6677
{

src/UriContext.php

+48-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,54 @@
2626
*/
2727
class UriContext
2828
{
29-
protected $collection;
30-
protected $translatedSubject;
31-
protected $locale;
32-
protected $uri;
33-
protected $autoRoute;
34-
protected $uriSchema;
35-
protected $tokenProviderConfigs;
36-
protected $conflictResolverConfig;
37-
protected $subjectMetadata;
38-
protected $defaults;
29+
/**
30+
* @var UriContextCollection
31+
*/
32+
private $collection;
33+
34+
/**
35+
* @var string
36+
*/
37+
private $uriSchema;
38+
39+
/**
40+
* @var array
41+
*/
42+
private $defaults;
43+
44+
/**
45+
* @var array
46+
*/
47+
private $tokenProviderConfigs;
48+
49+
/**
50+
* @var array
51+
*/
52+
private $conflictResolverConfig;
53+
54+
/**
55+
* The locale of the translatedSubject.
56+
*
57+
* If null, the subject is not translated.
58+
*
59+
* @var string
60+
*/
61+
private $locale;
62+
63+
/**
64+
* @var object
65+
*/
66+
private $translatedSubject;
67+
68+
/**
69+
* @var string
70+
*/
71+
private $uri;
72+
73+
/**
74+
* @var AutoRouteInterface
75+
*/
76+
private $autoRoute;
3977

4078
/**
4179
* Construct the context.

src/UriContextCollection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919
class UriContextCollection
2020
{
21-
protected $subject;
21+
private $subject;
2222

2323
/**
2424
* @var UriContext[]
2525
*/
26-
protected $uriContexts = [];
26+
private $uriContexts = [];
2727

2828
/**
2929
* Construct the collection for the given subject.

src/UriContextCollectionBuilder.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Cmf\Component\RoutingAuto;
1313

1414
use Metadata\MetadataFactoryInterface;
15+
use Symfony\Cmf\Component\RoutingAuto\Mapping\MetadataFactory;
1516

1617
/**
1718
* Class responsible for creating all the implied UriContext objects for
@@ -22,14 +23,14 @@
2223
class UriContextCollectionBuilder
2324
{
2425
/**
25-
* @var MetadataFactoryInterface
26+
* @var MetadataFactory
2627
*/
27-
protected $metadataFactory;
28+
private $metadataFactory;
2829

2930
/**
3031
* @var AdapterInterface
3132
*/
32-
protected $adapter;
33+
private $adapter;
3334

3435
public function __construct(MetadataFactoryInterface $metadataFactory, AdapterInterface $adapter)
3536
{

src/UriGenerator.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
*/
2121
class UriGenerator implements UriGeneratorInterface
2222
{
23-
protected $serviceRegistry;
24-
2523
/**
26-
* @param MetadataFactory the metadata factory
27-
* @param ServiceRegistry the auto route service registry
24+
* @var ServiceRegistry The auto route service registry
2825
*/
26+
private $serviceRegistry;
27+
2928
public function __construct(
3029
ServiceRegistry $serviceRegistry
3130
) {
@@ -62,7 +61,7 @@ public function generateUri(UriContext $uriContext)
6261

6362
$tokenValue = $tokenProvider->provideValue($uriContext, $tokenProviderOptions);
6463

65-
$isEmpty = empty($tokenValue) || $tokenValue == '/';
64+
$isEmpty = empty($tokenValue) || '/' === $tokenValue;
6665

6766
if ($isEmpty && false === $tokenProviderOptions['allow_empty']) {
6867
throw new \InvalidArgumentException(sprintf(
@@ -87,7 +86,7 @@ public function generateUri(UriContext $uriContext)
8786

8887
$uri = strtr($uriSchema, $tokens);
8988

90-
if (substr($uri, 0, 1) !== '/') {
89+
if ($uri[0] !== '/') {
9190
throw new \InvalidArgumentException(sprintf(
9291
'Generated non-absolute URI "%s" for object "%s"',
9392
$uri, get_class($uriContext->getSubject())
@@ -104,12 +103,10 @@ public function resolveConflict(UriContext $uriContext)
104103
{
105104
$conflictResolverConfig = $uriContext->getConflictResolverConfig();
106105
$conflictResolver = $this->serviceRegistry->getConflictResolver(
107-
$conflictResolverConfig['name'],
108-
$conflictResolverConfig['options']
106+
$conflictResolverConfig['name']
109107
);
110-
$uri = $conflictResolver->resolveConflict($uriContext);
111108

112-
return $uri;
109+
return $conflictResolver->resolveConflict($uriContext);
113110
}
114111

115112
/**

tests/Unit/Adapter/EventDispatchingAdapterTest.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ class EventDispatchingAdapterTest extends \PHPUnit_Framework_TestCase
5959
*/
6060
private $autoRoute2;
6161

62+
/**
63+
* @var object
64+
*/
6265
private $content;
6366

6467
public function setUp()
6568
{
66-
$this->realAdapter = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\AdapterInterface');
69+
$this->realAdapter = $this->prophesize(AdapterInterface::class);
6770
$this->dispatcher = new EventDispatcher();
6871
$this->adapter = new EventDispatchingAdapter(
6972
$this->realAdapter->reveal(),
@@ -72,9 +75,9 @@ public function setUp()
7275

7376
$this->subscriber = new EventDispatchingAdapterSubscriber();
7477
$this->dispatcher->addSubscriber($this->subscriber);
75-
$this->uriContext = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\UriContext');
76-
$this->autoRoute = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
77-
$this->autoRoute2 = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
78+
$this->uriContext = $this->prophesize(UriContext::class);
79+
$this->autoRoute = $this->prophesize(AutoRouteInterface::class);
80+
$this->autoRoute2 = $this->prophesize(AutoRouteInterface::class);
7881
$this->content = new \stdClass();
7982
}
8083

@@ -83,7 +86,7 @@ public function testCreateAutoRoute()
8386
$this->realAdapter->createAutoRoute($this->uriContext->reveal(), 'fr')->willReturn($this->autoRoute->reveal());
8487
$this->adapter->createAutoRoute($this->uriContext->reveal(), 'fr');
8588
$this->assertNotNull($this->subscriber->createEvent);
86-
$this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteCreateEvent', $this->subscriber->createEvent);
89+
$this->assertInstanceOf(AutoRouteCreateEvent::class, $this->subscriber->createEvent);
8790
$this->assertSame($this->autoRoute->reveal(), $this->subscriber->createEvent->getAutoRoute());
8891
$this->assertSame($this->uriContext->reveal(), $this->subscriber->createEvent->getUriContext());
8992
}
@@ -95,7 +98,7 @@ public function testMigrateAutoRouteChildren()
9598
$this->autoRoute2->reveal()
9699
);
97100
$this->assertNotNull($this->subscriber->migrateEvent);
98-
$this->assertInstanceOf('Symfony\Cmf\Component\RoutingAuto\Event\AutoRouteMigrateEvent', $this->subscriber->migrateEvent);
101+
$this->assertInstanceOf(AutoRouteMigrateEvent::class, $this->subscriber->migrateEvent);
99102
$this->assertSame($this->autoRoute->reveal(), $this->subscriber->migrateEvent->getSrcAutoRoute());
100103
$this->assertSame($this->autoRoute2->reveal(), $this->subscriber->migrateEvent->getDestAutoRoute());
101104
}

0 commit comments

Comments
 (0)