Skip to content

Commit 1166ef2

Browse files
Fix compatibility to JMS Serializer 5, remove ContainerAwareInterface usage and define requirement better (#91)
* Add requirement to doctrine orm * Do not install phpstan and php-cs-fixer for tests * Fix jms serializer compatibility * Fix PHPStan issues * Fix code style * Fix phpstan baseline
1 parent 8ecc5e7 commit 1166ef2

40 files changed

+178
-516
lines changed

.github/workflows/test-application.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ jobs:
4343
env:
4444
SYMFONY_DEPRECATIONS_HELPER: weak
4545

46+
- php-version: '8.2'
47+
dependency-versions: 'highest'
48+
php-extensions: 'mysql, imagick'
49+
tools: 'composer:v2'
50+
env:
51+
SYMFONY_DEPRECATIONS_HELPER: weak
52+
53+
- php-version: '8.3'
54+
dependency-versions: 'highest'
55+
php-extensions: 'mysql, imagick'
56+
tools: 'composer:v2'
57+
env:
58+
SYMFONY_DEPRECATIONS_HELPER: weak
59+
4660
services:
4761
mysql:
4862
image: 'mysql:5.7'
@@ -65,6 +79,9 @@ jobs:
6579
tools: '${{ matrix.tools }}'
6680
coverage: none
6781

82+
- name: Remove not required tooling for tests
83+
run: composer remove php-cs-fixer/shim "*phpstan*" --dev
84+
6885
- name: Install composer dependencies
6986
uses: ramsey/composer-install@v1
7087
with:

Admin/RedirectAdmin.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ public function configureViews(ViewCollection $viewCollection): void
134134
);
135135
}
136136

137-
/**
138-
* {@inheritdoc}
139-
*/
140137
public function getSecurityContexts()
141138
{
142139
return [

Command/ImportCommand.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public function __construct(FileImport $import)
3535
$this->import = $import;
3636
}
3737

38-
/**
39-
* {@inheritdoc}
40-
*/
4138
public function configure(): void
4239
{
4340
$this->addArgument('fileName', InputArgument::REQUIRED)
@@ -49,9 +46,6 @@ public function configure(): void
4946
);
5047
}
5148

52-
/**
53-
* {@inheritdoc}
54-
*/
5549
public function execute(InputInterface $input, OutputInterface $output)
5650
{
5751
$progressBar = new ProgressBar($output);

Controller/RedirectRouteImportController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Sulu\Bundle\RedirectBundle\Admin\RedirectAdmin;
1515
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterNotFoundException;
1616
use Sulu\Bundle\RedirectBundle\Import\FileImportInterface;
17+
use Sulu\Bundle\RedirectBundle\Import\ImportException;
1718
use Sulu\Bundle\RedirectBundle\Import\Item;
1819
use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderNotFoundException;
1920
use Sulu\Component\Security\SecuredControllerInterface;
@@ -47,17 +48,11 @@ public function __construct(FileImportInterface $import, $importPath)
4748
$this->importPath = $importPath;
4849
}
4950

50-
/**
51-
* {@inheritdoc}
52-
*/
5351
public function getSecurityContext(): string
5452
{
5553
return RedirectAdmin::SECURITY_CONTEXT;
5654
}
5755

58-
/**
59-
* {@inheritdoc}
60-
*/
6156
public function getLocale(Request $request)
6257
{
6358
return $request->get('locale', null);
@@ -94,7 +89,15 @@ public function postAction(Request $request)
9489
/**
9590
* Import given file and returns serializable response.
9691
*
97-
* @return array
92+
* @return array{
93+
* fileName: string,
94+
* total: int,
95+
* exceptions: array<array{
96+
* exception: null|ImportException,
97+
* lineNumber: int,
98+
* lineContent: string,
99+
* }>,
100+
* }
98101
*/
99102
private function importFile(File $file)
100103
{

DependencyInjection/Configuration.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
*/
2222
class Configuration implements ConfigurationInterface
2323
{
24-
/**
25-
* {@inheritdoc}
26-
*/
2724
public function getConfigTreeBuilder()
2825
{
2926
$treeBuilder = new TreeBuilder('sulu_redirect');

DependencyInjection/SuluRedirectExtension.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class SuluRedirectExtension extends Extension implements PrependExtensionInterfa
2828
{
2929
use PersistenceExtensionTrait;
3030

31-
/**
32-
* {@inheritdoc}
33-
*/
3431
public function prepend(ContainerBuilder $container): void
3532
{
3633
if ($container->hasExtension('jms_serializer')) {
@@ -91,9 +88,6 @@ public function prepend(ContainerBuilder $container): void
9188
}
9289
}
9390

94-
/**
95-
* {@inheritdoc}
96-
*/
9791
public function load(array $configs, ContainerBuilder $container): void
9892
{
9993
$configuration = new Configuration();

Entity/RedirectRoute.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,107 +52,71 @@ class RedirectRoute implements RedirectRouteInterface, AuditableInterface
5252
*/
5353
protected $target;
5454

55-
/**
56-
* {@inheritdoc}
57-
*/
5855
public function getId()
5956
{
6057
return $this->id;
6158
}
6259

63-
/**
64-
* {@inheritdoc}
65-
*/
6660
public function setId($id)
6761
{
6862
$this->id = $id;
6963

7064
return $this;
7165
}
7266

73-
/**
74-
* {@inheritdoc}
75-
*/
7667
public function isEnabled()
7768
{
7869
return $this->enabled;
7970
}
8071

81-
/**
82-
* {@inheritdoc}
83-
*/
8472
public function setEnabled($enabled)
8573
{
8674
$this->enabled = $enabled;
8775

8876
return $this;
8977
}
9078

91-
/**
92-
* {@inheritdoc}
93-
*/
9479
public function getStatusCode()
9580
{
9681
return $this->statusCode;
9782
}
9883

99-
/**
100-
* {@inheritdoc}
101-
*/
10284
public function setStatusCode($statusCode)
10385
{
10486
$this->statusCode = $statusCode;
10587

10688
return $this;
10789
}
10890

109-
/**
110-
* {@inheritdoc}
111-
*/
11291
public function getSource()
11392
{
11493
return $this->source;
11594
}
11695

117-
/**
118-
* {@inheritdoc}
119-
*/
12096
public function setSource($source)
12197
{
12298
$this->source = mb_strtolower('/' . ltrim($source, '/'));
12399

124100
return $this;
125101
}
126102

127-
/**
128-
* {@inheritdoc}
129-
*/
130103
public function getSourceHost()
131104
{
132105
return $this->sourceHost;
133106
}
134107

135-
/**
136-
* {@inheritdoc}
137-
*/
138108
public function setSourceHost($sourceHost)
139109
{
140110
$this->sourceHost = empty($sourceHost) ? null : mb_strtolower($sourceHost);
141111

142112
return $this;
143113
}
144114

145-
/**
146-
* {@inheritdoc}
147-
*/
148115
public function getTarget()
149116
{
150117
return $this->target;
151118
}
152119

153-
/**
154-
* {@inheritdoc}
155-
*/
156120
public function setTarget($target)
157121
{
158122
$this->target = $target;

Entity/RedirectRouteRepository.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
*/
2222
class RedirectRouteRepository extends EntityRepository implements RedirectRouteRepositoryInterface
2323
{
24-
/**
25-
* {@inheritdoc}
26-
*/
2724
public function findById($id)
2825
{
2926
/** @var RedirectRouteInterface|null $redirectRoute */
@@ -32,9 +29,6 @@ public function findById($id)
3229
return $redirectRoute;
3330
}
3431

35-
/**
36-
* {@inheritdoc}
37-
*/
3832
public function findEnabledBySource($source, $sourceHost = null)
3933
{
4034
$queryBuilder = $this->createFindBySourceQueryBuilder($source, $sourceHost);
@@ -43,27 +37,18 @@ public function findEnabledBySource($source, $sourceHost = null)
4337
return $queryBuilder->getQuery()->getOneOrNullResult();
4438
}
4539

46-
/**
47-
* {@inheritdoc}
48-
*/
4940
public function findBySource($source, $sourceHost = null)
5041
{
5142
$queryBuilder = $this->createFindBySourceQueryBuilder($source, $sourceHost);
5243

5344
return $queryBuilder->getQuery()->getOneOrNullResult();
5445
}
5546

56-
/**
57-
* {@inheritdoc}
58-
*/
5947
public function persist(RedirectRouteInterface $entity): void
6048
{
6149
$this->_em->persist($entity);
6250
}
6351

64-
/**
65-
* {@inheritdoc}
66-
*/
6752
public function remove(RedirectRouteInterface $entity): void
6853
{
6954
$this->_em->remove($entity);

GoneSubscriber/GoneDocumentSubscriber.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
/**
2727
* This gone subscriber listens for removed pages.
28+
*
29+
* @internal this is a internal listener which should not be used directly
2830
*/
2931
class GoneDocumentSubscriber implements EventSubscriberInterface
3032
{
@@ -77,9 +79,6 @@ public function __construct(
7779
$this->environment = $environment;
7880
}
7981

80-
/**
81-
* {@inheritdoc}
82-
*/
8382
public static function getSubscribedEvents()
8483
{
8584
return [
@@ -113,7 +112,7 @@ public function createRedirects(RemoveEvent $event): void
113112
}
114113

115114
/**
116-
* @return array
115+
* @return string[]
117116
*/
118117
protected function getUrls(BasePageDocument $document)
119118
{
@@ -166,7 +165,7 @@ protected function getUrls(BasePageDocument $document)
166165
* @param string $webspaceKey
167166
* @param string $locale
168167
*
169-
* @return array
168+
* @return string[]
170169
*/
171170
protected function getHistoryUrls(
172171
ResourceLocatorStrategyInterface $resourceLocatorStrategy,

GoneSubscriber/GoneEntitySubscriber.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@
1616
use Doctrine\ORM\Events;
1717
use Sulu\Bundle\RedirectBundle\Entity\RedirectRoute;
1818
use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException;
19-
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManager;
19+
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManagerInterface;
2020
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
2121
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2222
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
2323

2424
/**
2525
* This gone subscriber listens for removed route entities.
26+
*
27+
* @internal this is a internal listener which should not be used directly
2628
*/
2729
class GoneEntitySubscriber implements EventSubscriber, ContainerAwareInterface
2830
{
2931
use ContainerAwareTrait;
3032

3133
/**
32-
* {@inheritdoc}
34+
* @var RedirectRouteManagerInterface
3335
*/
36+
private $redirectRouteManager;
37+
38+
public function __construct(
39+
RedirectRouteManagerInterface $redirectRouteManager
40+
) {
41+
$this->redirectRouteManager = $redirectRouteManager;
42+
}
43+
3444
public function getSubscribedEvents()
3545
{
3646
return [
@@ -42,8 +52,7 @@ public function preRemove(LifecycleEventArgs $event): void
4252
{
4353
$route = $event->getObject();
4454

45-
$routeManager = $this->getRedirectRouteManager();
46-
if (!$route instanceof RouteInterface || null === $routeManager) {
55+
if (!$route instanceof RouteInterface) {
4756
return;
4857
}
4958

@@ -53,21 +62,9 @@ public function preRemove(LifecycleEventArgs $event): void
5362
$redirectRoute->setSource($route->getPath());
5463

5564
try {
56-
$routeManager->save($redirectRoute);
65+
$this->redirectRouteManager->save($redirectRoute);
5766
} catch (RedirectRouteNotUniqueException $exception) {
5867
// do nothing when there already exists a redirect route
5968
}
6069
}
61-
62-
/**
63-
* @return RedirectRouteManager|null
64-
*/
65-
private function getRedirectRouteManager()
66-
{
67-
if (null === $this->container) {
68-
return null;
69-
}
70-
71-
return $this->container->get('sulu_redirect.redirect_route_manager');
72-
}
7370
}

0 commit comments

Comments
 (0)