Skip to content

Commit

Permalink
Fix compatibility to JMS Serializer 5, remove ContainerAwareInterface…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
alexander-schranz authored Jun 6, 2024
1 parent 8ecc5e7 commit 1166ef2
Show file tree
Hide file tree
Showing 40 changed files with 178 additions and 516 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ jobs:
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.2'
dependency-versions: 'highest'
php-extensions: 'mysql, imagick'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.3'
dependency-versions: 'highest'
php-extensions: 'mysql, imagick'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

services:
mysql:
image: 'mysql:5.7'
Expand All @@ -65,6 +79,9 @@ jobs:
tools: '${{ matrix.tools }}'
coverage: none

- name: Remove not required tooling for tests
run: composer remove php-cs-fixer/shim "*phpstan*" --dev

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
Expand Down
3 changes: 0 additions & 3 deletions Admin/RedirectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ public function configureViews(ViewCollection $viewCollection): void
);
}

/**
* {@inheritdoc}
*/
public function getSecurityContexts()
{
return [
Expand Down
6 changes: 0 additions & 6 deletions Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public function __construct(FileImport $import)
$this->import = $import;
}

/**
* {@inheritdoc}
*/
public function configure(): void
{
$this->addArgument('fileName', InputArgument::REQUIRED)
Expand All @@ -49,9 +46,6 @@ public function configure(): void
);
}

/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$progressBar = new ProgressBar($output);
Expand Down
17 changes: 10 additions & 7 deletions Controller/RedirectRouteImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sulu\Bundle\RedirectBundle\Admin\RedirectAdmin;
use Sulu\Bundle\RedirectBundle\Import\Converter\ConverterNotFoundException;
use Sulu\Bundle\RedirectBundle\Import\FileImportInterface;
use Sulu\Bundle\RedirectBundle\Import\ImportException;
use Sulu\Bundle\RedirectBundle\Import\Item;
use Sulu\Bundle\RedirectBundle\Import\Reader\ReaderNotFoundException;
use Sulu\Component\Security\SecuredControllerInterface;
Expand Down Expand Up @@ -47,17 +48,11 @@ public function __construct(FileImportInterface $import, $importPath)
$this->importPath = $importPath;
}

/**
* {@inheritdoc}
*/
public function getSecurityContext(): string
{
return RedirectAdmin::SECURITY_CONTEXT;
}

/**
* {@inheritdoc}
*/
public function getLocale(Request $request)
{
return $request->get('locale', null);
Expand Down Expand Up @@ -94,7 +89,15 @@ public function postAction(Request $request)
/**
* Import given file and returns serializable response.
*
* @return array
* @return array{
* fileName: string,
* total: int,
* exceptions: array<array{
* exception: null|ImportException,
* lineNumber: int,
* lineContent: string,
* }>,
* }
*/
private function importFile(File $file)
{
Expand Down
3 changes: 0 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('sulu_redirect');
Expand Down
6 changes: 0 additions & 6 deletions DependencyInjection/SuluRedirectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class SuluRedirectExtension extends Extension implements PrependExtensionInterfa
{
use PersistenceExtensionTrait;

/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container): void
{
if ($container->hasExtension('jms_serializer')) {
Expand Down Expand Up @@ -91,9 +88,6 @@ public function prepend(ContainerBuilder $container): void
}
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand Down
36 changes: 0 additions & 36 deletions Entity/RedirectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,107 +52,71 @@ class RedirectRoute implements RedirectRouteInterface, AuditableInterface
*/
protected $target;

/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}

/**
* {@inheritdoc}
*/
public function setId($id)
{
$this->id = $id;

return $this;
}

/**
* {@inheritdoc}
*/
public function isEnabled()
{
return $this->enabled;
}

/**
* {@inheritdoc}
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;

return $this;
}

/**
* {@inheritdoc}
*/
public function getStatusCode()
{
return $this->statusCode;
}

/**
* {@inheritdoc}
*/
public function setStatusCode($statusCode)
{
$this->statusCode = $statusCode;

return $this;
}

/**
* {@inheritdoc}
*/
public function getSource()
{
return $this->source;
}

/**
* {@inheritdoc}
*/
public function setSource($source)
{
$this->source = mb_strtolower('/' . ltrim($source, '/'));

return $this;
}

/**
* {@inheritdoc}
*/
public function getSourceHost()
{
return $this->sourceHost;
}

/**
* {@inheritdoc}
*/
public function setSourceHost($sourceHost)
{
$this->sourceHost = empty($sourceHost) ? null : mb_strtolower($sourceHost);

return $this;
}

/**
* {@inheritdoc}
*/
public function getTarget()
{
return $this->target;
}

/**
* {@inheritdoc}
*/
public function setTarget($target)
{
$this->target = $target;
Expand Down
15 changes: 0 additions & 15 deletions Entity/RedirectRouteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
*/
class RedirectRouteRepository extends EntityRepository implements RedirectRouteRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function findById($id)
{
/** @var RedirectRouteInterface|null $redirectRoute */
Expand All @@ -32,9 +29,6 @@ public function findById($id)
return $redirectRoute;
}

/**
* {@inheritdoc}
*/
public function findEnabledBySource($source, $sourceHost = null)
{
$queryBuilder = $this->createFindBySourceQueryBuilder($source, $sourceHost);
Expand All @@ -43,27 +37,18 @@ public function findEnabledBySource($source, $sourceHost = null)
return $queryBuilder->getQuery()->getOneOrNullResult();
}

/**
* {@inheritdoc}
*/
public function findBySource($source, $sourceHost = null)
{
$queryBuilder = $this->createFindBySourceQueryBuilder($source, $sourceHost);

return $queryBuilder->getQuery()->getOneOrNullResult();
}

/**
* {@inheritdoc}
*/
public function persist(RedirectRouteInterface $entity): void
{
$this->_em->persist($entity);
}

/**
* {@inheritdoc}
*/
public function remove(RedirectRouteInterface $entity): void
{
$this->_em->remove($entity);
Expand Down
9 changes: 4 additions & 5 deletions GoneSubscriber/GoneDocumentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

/**
* This gone subscriber listens for removed pages.
*
* @internal this is a internal listener which should not be used directly
*/
class GoneDocumentSubscriber implements EventSubscriberInterface
{
Expand Down Expand Up @@ -77,9 +79,6 @@ public function __construct(
$this->environment = $environment;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
Expand Down Expand Up @@ -113,7 +112,7 @@ public function createRedirects(RemoveEvent $event): void
}

/**
* @return array
* @return string[]
*/
protected function getUrls(BasePageDocument $document)
{
Expand Down Expand Up @@ -166,7 +165,7 @@ protected function getUrls(BasePageDocument $document)
* @param string $webspaceKey
* @param string $locale
*
* @return array
* @return string[]
*/
protected function getHistoryUrls(
ResourceLocatorStrategyInterface $resourceLocatorStrategy,
Expand Down
31 changes: 14 additions & 17 deletions GoneSubscriber/GoneEntitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,31 @@
use Doctrine\ORM\Events;
use Sulu\Bundle\RedirectBundle\Entity\RedirectRoute;
use Sulu\Bundle\RedirectBundle\Exception\RedirectRouteNotUniqueException;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManager;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManagerInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

/**
* This gone subscriber listens for removed route entities.
*
* @internal this is a internal listener which should not be used directly
*/
class GoneEntitySubscriber implements EventSubscriber, ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* {@inheritdoc}
* @var RedirectRouteManagerInterface
*/
private $redirectRouteManager;

public function __construct(
RedirectRouteManagerInterface $redirectRouteManager
) {
$this->redirectRouteManager = $redirectRouteManager;
}

public function getSubscribedEvents()
{
return [
Expand All @@ -42,8 +52,7 @@ public function preRemove(LifecycleEventArgs $event): void
{
$route = $event->getObject();

$routeManager = $this->getRedirectRouteManager();
if (!$route instanceof RouteInterface || null === $routeManager) {
if (!$route instanceof RouteInterface) {
return;
}

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

try {
$routeManager->save($redirectRoute);
$this->redirectRouteManager->save($redirectRoute);
} catch (RedirectRouteNotUniqueException $exception) {
// do nothing when there already exists a redirect route
}
}

/**
* @return RedirectRouteManager|null
*/
private function getRedirectRouteManager()
{
if (null === $this->container) {
return null;
}

return $this->container->get('sulu_redirect.redirect_route_manager');
}
}
Loading

0 comments on commit 1166ef2

Please sign in to comment.