Skip to content

Commit e2f35a3

Browse files
authored
Merge pull request #219 from stephpy/symfony5
Symfony5
2 parents 207adaf + 882cbf7 commit e2f35a3

File tree

10 files changed

+167
-227
lines changed

10 files changed

+167
-227
lines changed

DependencyInjection/Compiler/AddSpreadCompilerPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7+
use Symfony\Component\DependencyInjection\Reference;
78

89
class AddSpreadCompilerPass implements CompilerPassInterface
910
{
@@ -17,11 +18,10 @@ public function process(ContainerBuilder $container)
1718
$spreadByPriority = [];
1819

1920
foreach ($container->findTaggedServiceIds('spy_timeline.spread') as $id => $options) {
20-
$priority = isset($attributes[0]['priority']) ? $options[0]['priority'] : 0;
21-
22-
$spreadByPriority[$priority][] = $container->getDefinition($id);
21+
$priority = isset($attributes[0]['priority']) ? $options[0]['priority'] : 0;
22+
$spreadByPriority[$priority][] = new Reference($id);
2323
}
24-
24+
2525
if (empty($spreadByPriority)) {
2626
return;
2727
}

DependencyInjection/Configuration.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Configuration implements ConfigurationInterface
1515
*/
1616
public function getConfigTreeBuilder()
1717
{
18-
$tb = new TreeBuilder();
19-
$rootNode = $tb->root('spy_timeline');
18+
$tb = new TreeBuilder('spy_timeline');
19+
$rootNode = $tb->getRootNode();
2020

2121
$this->addDriverSection($rootNode);
2222
$this->addQueryBuilderSection($rootNode);
@@ -56,25 +56,25 @@ protected function addDriverSection($rootNode)
5656
$rootNode
5757
->validate()
5858
->ifTrue(function ($v) {
59-
if (!isset($v['drivers']) || count($v['drivers']) == 0) {
59+
if (!isset($v['drivers']) || 0 == \count($v['drivers'])) {
6060
return !isset($v['timeline_manager']) || !isset($v['action_manager']);
6161
}
6262

6363
return false;
6464
})
65-
->thenInvalid("Please define a driver or timeline_manager, action_manager")
65+
->thenInvalid('Please define a driver or timeline_manager, action_manager')
6666
->end()
6767
->validate()
6868
->ifTrue(function ($v) {
69-
return isset($v['drivers']) && isset($v['drivers']['redis']) && $v['spread']['delivery'] != 'immediate';
69+
return isset($v['drivers']) && isset($v['drivers']['redis']) && 'immediate' != $v['spread']['delivery'];
7070
})
71-
->thenInvalid("Redis driver accepts only spread delivery immediate.")
71+
->thenInvalid('Redis driver accepts only spread delivery immediate.')
7272
->end()
7373
->children()
7474
->arrayNode('drivers')
7575
->validate()
7676
->ifTrue(function ($v) {
77-
return count($v) > 1;
77+
return \count($v) > 1;
7878
})
7979
->thenInvalid('Please define only one driver.')
8080
->end()
@@ -234,9 +234,9 @@ protected function addFilterSection($rootNode)
234234
->scalarNode('service')->defaultValue('spy_timeline.filter.data_hydrator')->end()
235235
->booleanNode('filter_unresolved')->defaultTrue()->end()
236236
->arrayNode('locators')
237-
->example(array(
237+
->example([
238238
'spy_timeline.filter.data_hydrator.locator.doctrine',
239-
))
239+
])
240240
->prototype('scalar')
241241
->end()
242242
->end()
@@ -283,11 +283,11 @@ protected function addRenderSection($rootNode)
283283
->end()
284284
->end()
285285
->arrayNode('resources')
286-
->defaultValue(array('@SpyTimeline/Action/components.html.twig'))
286+
->defaultValue(['@SpyTimeline/Action/components.html.twig'])
287287
->validate()
288-
->ifTrue(function ($v) { return !in_array('@SpyTimeline/Action/components.html.twig', $v); })
288+
->ifTrue(function ($v) { return !\in_array('@SpyTimeline/Action/components.html.twig', $v); })
289289
->then(function ($v) {
290-
return array_merge(array('@SpyTimeline/Action/components.html.twig'), $v);
290+
return array_merge(['@SpyTimeline/Action/components.html.twig'], $v);
291291
})
292292
->end()
293293
->prototype('scalar')->end()

Driver/Doctrine/AbstractActionManager.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Spy\TimelineBundle\Driver\Doctrine;
44

55
use Doctrine\Common\Persistence\ObjectManager;
6-
use Spy\Timeline\Model\ActionInterface;
7-
use Spy\Timeline\ResultBuilder\ResultBuilderInterface;
6+
use Doctrine\ORM\EntityManager;
87
use Spy\Timeline\Driver\AbstractActionManager as BaseActionManager;
8+
use Spy\Timeline\Model\ActionInterface;
99
use Spy\Timeline\Model\ComponentInterface;
1010
use Spy\Timeline\ResolveComponent\ValueObject\ResolvedComponentData;
11+
use Spy\Timeline\ResultBuilder\ResultBuilderInterface;
1112

1213
abstract class AbstractActionManager extends BaseActionManager
1314
{
@@ -28,17 +29,14 @@ abstract class AbstractActionManager extends BaseActionManager
2829
* @param string $componentClass componentClass
2930
* @param string $actionComponentClass actionComponentClass
3031
*/
31-
public function __construct(ObjectManager $objectManager, ResultBuilderInterface $resultBuilder, $actionClass, $componentClass, $actionComponentClass)
32+
public function __construct(EntityManager $objectManager, ResultBuilderInterface $resultBuilder, $actionClass, $componentClass, $actionComponentClass)
3233
{
33-
$this->objectManager = $objectManager;
34-
$this->resultBuilder = $resultBuilder;
34+
$this->objectManager = $objectManager;
35+
$this->resultBuilder = $resultBuilder;
3536

3637
parent::__construct($actionClass, $componentClass, $actionComponentClass);
3738
}
3839

39-
/**
40-
* {@inheritdoc}
41-
*/
4240
public function updateAction(ActionInterface $action)
4341
{
4442
$this->objectManager->persist($action);
@@ -47,19 +45,13 @@ public function updateAction(ActionInterface $action)
4745
$this->deployActionDependOnDelivery($action);
4846
}
4947

50-
/**
51-
* {@inheritdoc}
52-
*/
5348
public function createComponent($model, $identifier = null, $flush = true)
5449
{
5550
$resolvedComponentData = $this->resolveModelAndIdentifier($model, $identifier);
5651

5752
return $this->createComponentFromResolvedComponentData($resolvedComponentData, $flush);
5853
}
5954

60-
/**
61-
* {@inheritdoc}
62-
*/
6355
public function flushComponents()
6456
{
6557
$this->objectManager->flush();
@@ -69,7 +61,7 @@ public function flushComponents()
6961
* Creates a component from a resolved model and identifier and optionally stores it to the storage engine.
7062
*
7163
* @param ResolvedComponentData $resolved The resolved component data
72-
* @param boolean $flush Whether to flush or not, defaults to true
64+
* @param bool $flush Whether to flush or not, defaults to true
7365
*
7466
* @return ComponentInterface The newly created and populated component
7567
*/

Driver/Doctrine/AbstractTimelineManager.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spy\TimelineBundle\Driver\Doctrine;
44

55
use Doctrine\Common\Persistence\ObjectManager;
6+
use Doctrine\ORM\EntityManager;
67
use Spy\Timeline\Model\ActionInterface;
78
use Spy\Timeline\Model\ComponentInterface;
89
use Spy\Timeline\Model\TimelineInterface;
@@ -30,16 +31,13 @@ class AbstractTimelineManager
3031
* @param ResultBuilderInterface $resultBuilder resultBuilder
3132
* @param string $timelineClass timelineClass
3233
*/
33-
public function __construct(ObjectManager $objectManager, ResultBuilderInterface $resultBuilder, $timelineClass)
34+
public function __construct(EntityManager $objectManager, ResultBuilderInterface $resultBuilder, $timelineClass)
3435
{
3536
$this->objectManager = $objectManager;
3637
$this->resultBuilder = $resultBuilder;
3738
$this->timelineClass = $timelineClass;
3839
}
3940

40-
/**
41-
* {@inheritdoc}
42-
*/
4341
public function createAndPersist(ActionInterface $action, ComponentInterface $subject, $context = 'GLOBAL', $type = TimelineInterface::TYPE_TIMELINE)
4442
{
4543
/** @var TimelineInterface $timeline */

Driver/ORM/Pager.php

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,23 @@ class Pager implements PagerInterface, \IteratorAggregate, \Countable, \ArrayAcc
1111
/**
1212
* @var array
1313
*/
14-
protected $items = array();
14+
protected $items = [];
1515

1616
/**
17-
* @var integer
17+
* @var int
1818
*/
1919
protected $lastPage;
2020

2121
/**
22-
* @var integer
22+
* @var int
2323
*/
2424
protected $page;
2525

2626
/**
27-
* @var integer
27+
* @var int
2828
*/
2929
protected $nbResults;
3030

31-
/**
32-
* {@inheritdoc}
33-
*/
3431
public function paginate($target, $page = 1, $limit = 10)
3532
{
3633
if (!$target instanceof DoctrineQueryBuilder) {
@@ -46,42 +43,33 @@ public function paginate($target, $page = 1, $limit = 10)
4643
;
4744
}
4845

49-
$paginator = new Paginator($target, true);
50-
$this->page = $page;
51-
$this->items = (array) $paginator->getIterator();
52-
$this->nbResults = count($paginator);
53-
$this->lastPage = intval(ceil($this->nbResults / $limit));
46+
$paginator = new Paginator($target, true);
47+
$this->page = $page;
48+
$this->items = (array) $paginator->getIterator();
49+
$this->nbResults = \count($paginator);
50+
$this->lastPage = (int) ceil($this->nbResults / $limit);
51+
52+
// Clone is not the best design here but we should not have any state
53+
// on this pager or at least it should not be injected on services with state.
5454

55-
return $this;
55+
return clone $this;
5656
}
5757

58-
/**
59-
* {@inheritdoc}
60-
*/
6158
public function getLastPage()
6259
{
6360
return $this->lastPage;
6461
}
6562

66-
/**
67-
* {@inheritdoc}
68-
*/
6963
public function getPage()
7064
{
7165
return $this->page;
7266
}
7367

74-
/**
75-
* {@inheritdoc}
76-
*/
7768
public function haveToPaginate()
7869
{
7970
return $this->getLastPage() > 1;
8071
}
8172

82-
/**
83-
* {@inheritdoc}
84-
*/
8573
public function getNbResults()
8674
{
8775
return $this->nbResults;
@@ -104,47 +92,35 @@ public function getIterator()
10492
}
10593

10694
/**
107-
* @return integer
95+
* @return int
10896
*/
10997
public function count()
11098
{
111-
return count($this->items);
99+
return \count($this->items);
112100
}
113101

114-
/**
115-
* @param mixed $offset
116-
* @param mixed $value
117-
*/
118102
public function offsetSet($offset, $value)
119103
{
120-
if (is_null($offset)) {
104+
if (null === $offset) {
121105
$this->items[] = $value;
122106
} else {
123107
$this->items[$offset] = $value;
124108
}
125109
}
126110

127111
/**
128-
* @param mixed $offset
129-
* @return boolean
112+
* @return bool
130113
*/
131114
public function offsetExists($offset)
132115
{
133116
return isset($this->items[$offset]);
134117
}
135118

136-
/**
137-
* @param mixed $offset
138-
*/
139119
public function offsetUnset($offset)
140120
{
141121
unset($this->items[$offset]);
142122
}
143123

144-
/**
145-
* @param mixed $offset
146-
* @return mixed
147-
*/
148124
public function offsetGet($offset)
149125
{
150126
return isset($this->items[$offset]) ? $this->items[$offset] : null;

0 commit comments

Comments
 (0)