Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations #447

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
"require": {
"php": "^8.1",
"ext-pcre": "*",
"sonata-project/datagrid-bundle": "^2.3 || ^3.0",
"symfony/routing": "^5.4 || ^6.2",
"symfony/translation-contracts": "^1.1 || ^2.0 || ^3.0",
"symfony/translation-contracts": "^2.0 || ^3.0",
"twig/twig": "^2.4 || ^3.0"
},
"require-dev": {
Expand Down
52 changes: 0 additions & 52 deletions src/Bridge/Symfony/DependencyInjection/Configuration.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ final class NucleosTwigExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.php');

$container->getDefinition('nucleos_twig.router.extension')
->replaceArgument(2, $config['pagination'])
;
}
}
2 changes: 0 additions & 2 deletions src/Bridge/Symfony/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
->set('nucleos_twig.router.extension', RouterTwigExtension::class)
->tag('twig.extension')
->args([
new Reference('twig'),
new Reference('router'),
[],
])
;
};
71 changes: 0 additions & 71 deletions src/Bridge/Symfony/Resources/views/Pager/pagination.html.twig

This file was deleted.

65 changes: 2 additions & 63 deletions src/Extension/RouterTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@

namespace Nucleos\Twig\Extension;

use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
Expand All @@ -25,43 +20,15 @@
{
private RouterInterface $router;

/**
* @var array<string, int|string>
*/
private array $options;

private Environment $environment;

/**
* @param array<string, int|string> $options
*
* @throws LoaderError
*/
public function __construct(Environment $environment, RouterInterface $router, array $options = [])
public function __construct(RouterInterface $router)
{
$this->environment = $environment;
$this->router = $router;
$this->options = $options;

if (!isset($this->options['template'])) {
throw new LoaderError('Pager template is not set.');
}
if (!isset($this->options['extremeLimit'])) {
throw new LoaderError('Pager extreme limit is not set.');
}
if (!isset($this->options['nearbyLimit'])) {
throw new LoaderError('Pager nearby limit is not set.');
}
$this->router = $router;
}

public function getFunctions(): array
{
return [
new TwigFunction('routeExists', [$this, 'routeExists']),
new TwigFunction('page_pager', [$this, 'generatePager'], [
'is_safe' => ['html'],
'deprecated' => true,
]),
];
}

Expand All @@ -82,44 +49,16 @@
*/
public function splitTag(string $text, string $tag): array
{
if ('' === trim($tag)) {

Check warning on line 52 in src/Extension/RouterTwigExtension.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ */ public function splitTag(string $text, string $tag) : array { - if ('' === trim($tag)) { + if ('' === $tag) { return [$text]; } $split = preg_split('/(?=<' . $tag . '([^>])*>)/', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
return [$text];
}

$split = preg_split('/(?=<'.$tag.'([^>])*>)/', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

if (false !== $split) {

Check warning on line 58 in src/Extension/RouterTwigExtension.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ return [$text]; } $split = preg_split('/(?=<' . $tag . '([^>])*>)/', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - if (false !== $split) { + if (true !== $split) { return $split; } return [$text]; } }
return $split;
}

return [$text];
}

/**
* @param PagerInterface<object> $pager
* @param array<string, int|string> $options
*
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*
* @deprecated
*/
public function generatePager(PagerInterface $pager, array $options = []): string
{
$data = array_merge(array_merge($this->options, $options), [
'itemsCount' => $pager->count(),
'limit' => max(1, $pager->getMaxPerPage()),
'currentPage' => $pager->getPage(),
]);

$data['lastPage'] = self::getNumPages((int) $data['limit'], (int) $data['itemsCount']);

return $this->environment->render((string) $data['template'], $data);
}

private static function getNumPages(int $limit, int $count): int
{
return (int) ceil($count / $limit);
}
}
4 changes: 2 additions & 2 deletions tests/Bridge/Symfony/Bundle/NucleosTwigBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public function testGetPath(): void
{
$bundle = new NucleosTwigBundle();

static::assertStringEndsWith('Bridge/Symfony/Bundle', \dirname($bundle->getPath()));
self::assertStringEndsWith('Bridge/Symfony/Bundle', \dirname($bundle->getPath()));
}

public function testGetContainerExtension(): void
{
$bundle = new NucleosTwigBundle();

static::assertInstanceOf(NucleosTwigExtension::class, $bundle->getContainerExtension());
self::assertInstanceOf(NucleosTwigExtension::class, $bundle->getContainerExtension());
}
}
60 changes: 0 additions & 60 deletions tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,6 @@ public function testLoadDefault(): void
);
$this->assertContainerBuilderHasService('nucleos_twig.string.extension', StringTwigExtension::class);
$this->assertContainerBuilderHasService('nucleos_twig.router.extension', RouterTwigExtension::class);

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
'nucleos_twig.router.extension',
2,
[
'template' => '@NucleosTwig/Pager/pagination.html.twig',
'extremeLimit' => 3,
'nearbyLimit' => 2,
]
);
}

public function testLoadCustom(): void
{
$this->load(
[
'pagination' => [
'template' => '@Acme/Pager/pagination.html.twig',
'extremeLimit' => 10,
'nearbyLimit' => 5,
],
]
);

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
'nucleos_twig.router.extension',
2,
[
'template' => '@Acme/Pager/pagination.html.twig',
'extremeLimit' => 10,
'nearbyLimit' => 5,
]
);
}

protected function getContainerExtensions(): array
Expand Down