Skip to content

Commit

Permalink
DevKit updates for 3.x branch (#1544)
Browse files Browse the repository at this point in the history
* DevKit updates

* Fix cs

Co-authored-by: Vincent Langlet <[email protected]>
  • Loading branch information
SonataCI and VincentLanglet authored Aug 11, 2022
1 parent 25cde10 commit dff04de
Show file tree
Hide file tree
Showing 28 changed files with 153 additions and 168 deletions.
20 changes: 4 additions & 16 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,26 @@
HEADER;

$rules = [
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit57Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PSR12' => true,
'@PSR12:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_extra_blank_lines' => true,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_useless_else' => true,
'no_useless_return' => true,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'ordered_class_elements' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'function', 'const']],
'php_unit_method_casing' => false,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => false,
'php_unit_test_case_static_method_calls' => true,
'phpdoc_order' => true,
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']],
'single_line_throw' => false,
'static_lambda' => true,
Expand Down
8 changes: 4 additions & 4 deletions src/Admin/Extension/CreateSnapshotAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CreateSnapshotAdminExtension extends AbstractAdminExtension
*/
protected $backend;

//NEXT_MAJOR: restrict type to CreateSnapshotByPageInterface
// NEXT_MAJOR: restrict type to CreateSnapshotByPageInterface
public function __construct($backend)
{
$this->backend = $backend;
Expand Down Expand Up @@ -65,15 +65,15 @@ protected function sendMessage($object)
{
if ($object instanceof BlockInterface && method_exists($object, 'getPage')) {
$page = $object->getPage();
$pageId = $page->getId(); //NEXT_MAJOR: Remove this line.
$pageId = $page->getId(); // NEXT_MAJOR: Remove this line.
} elseif ($object instanceof PageInterface) {
$page = $object;
$pageId = $page->getId(); //NEXT_MAJOR: Remove this line.
$pageId = $page->getId(); // NEXT_MAJOR: Remove this line.
} else {
return;
}

//NEXT_MAJOR: Remove the if code and all code related with BackendInterface
// NEXT_MAJOR: Remove the if code and all code related with BackendInterface
if ($this->backend instanceof BackendInterface) {
@trigger_error(
sprintf(
Expand Down
2 changes: 1 addition & 1 deletion src/Block/BreadcrumbBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getName()

public function getBlockMetadata($code = null)
{
return new Metadata($this->getName(), ($code ?? $this->getName()), false, 'SonataPageBundle', [
return new Metadata($this->getName(), $code ?? $this->getName(), false, 'SonataPageBundle', [
'class' => 'fa fa-bars',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Block/ContainerBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function configureSettings(OptionsResolver $resolver)

public function getBlockMetadata($code = null)
{
return new Metadata($this->getName(), ($code ?? $this->getName()), false, 'SonataPageBundle', [
return new Metadata($this->getName(), $code ?? $this->getName(), false, 'SonataPageBundle', [
'class' => 'fa fa-square-o',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Block/PageListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function configureSettings(OptionsResolver $resolver)

public function getBlockMetadata($code = null)
{
return new Metadata($this->getName(), ($code ?? $this->getName()), false, 'SonataPageBundle', [
return new Metadata($this->getName(), $code ?? $this->getName(), false, 'SonataPageBundle', [
'class' => 'fa fa-home',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CmsManager/DecoratorStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function isDecorable(Request $request, $requestType, Response $response)
return false;
}

if ('text/html' !== (substr($response->headers->get('Content-Type') ?: 'text/html', 0, 9))) {
if ('text/html' !== substr($response->headers->get('Content-Type') ?: 'text/html', 0, 9)) {
return false;
}

Expand Down
18 changes: 9 additions & 9 deletions src/Command/CleanupSnapshotsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public function configure()
$this->setDescription('Cleanups the deprecated snapshots by a given site');

$this->addOption('site', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Site id');
//NEXT_MAJOR: Remove the "base-console" option.
// NEXT_MAJOR: Remove the "base-console" option.
$this->addOption('base-console', null, InputOption::VALUE_OPTIONAL, 'Base Symfony console command', 'app/console');
//NEXT_MAJOR: Remove the "mode" option.
// NEXT_MAJOR: Remove the "mode" option.
$this->addOption('mode', null, InputOption::VALUE_OPTIONAL, 'Run the command asynchronously', 'sync');
$this->addOption('keep-snapshots', null, InputOption::VALUE_OPTIONAL, 'Keep a given count of snapshots per page', 5);
}

protected function initialize(InputInterface $input, OutputInterface $output)
{
//NEXT_MAJOR: Remove this condition.
// NEXT_MAJOR: Remove this condition.
if ('app/console' !== $input->getOption('base-console')) {
@trigger_error(
'The "base-console" is deprecated since sonata-project/page-bundle 3.27.0 and will be removed in 4.0',
\E_USER_DEPRECATED
);
}

//NEXT_MAJOR: Remove this condition.
// NEXT_MAJOR: Remove this condition.
if (!\in_array($input->getOption('mode'), ['async', 'sync'], true)) {
throw new \InvalidArgumentException('Option "mode" is not valid (async|sync).');
}
Expand All @@ -66,14 +66,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$siteOption = $input->getOption('site');
$keepSnapshots = $input->getOption('keep-snapshots');

//NEXT_MAJOR: Remove this condition, because site will be optional.
// NEXT_MAJOR: Remove this condition, because site will be optional.
if ([] === $siteOption) {
$output->writeln('Please provide an <info>--site=SITE_ID</info> option or the <info>--site=all</info> directive');

return 1;
}

//NEXT_MAJOR: Remove this block condition.
// NEXT_MAJOR: Remove this block condition.
if (['all'] === $siteOption) {
@trigger_error(
sprintf(
Expand All @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($this->getSites($siteOption) as $site) {
//NEXT_MAJOR: Remove this "async" block condition.
// NEXT_MAJOR: Remove this "async" block condition.
if ('async' === $input->getOption('mode')) {
@trigger_error(
'The async mode is deprecated since sonata-project/page-bundle 3.27.0 and will be removed in 4.0',
Expand All @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->write(sprintf('<info>%s</info> - Cleaning up snapshots ...', $site->getName()));

//NEXT_MAJOR: inject this class in the constructor CleanupSnapshotBySiteInterface $cleanupSnapshot
// NEXT_MAJOR: inject this class in the constructor CleanupSnapshotBySiteInterface $cleanupSnapshot
$cleanupSnapshot = $this->getContainer()->get('sonata.page.service.cleanup_snapshot');
$cleanupSnapshot->cleanupBySite($site, $keepSnapshots);

Expand All @@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getSites($ids): array
{
//NEXT_MAJOR: Inject this on the __construct.
// NEXT_MAJOR: Inject this on the __construct.
$siteManager = $this->getContainer()->get('sonata.page.manager.site');

if ([] === $ids) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CloneSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

//NEXT_MAJOR: Remove this target condition block.
// NEXT_MAJOR: Remove this target condition block.
if ($page->getTarget()) {
@trigger_error(
'target page is deprecate since sonata-project/page-bundle 3.27.0'.
Expand Down
14 changes: 7 additions & 7 deletions src/Command/CreateSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function configure()

$this->setHelp(
<<<'EOT'
The <info>sonata:page:create-site</info> command create a new site entity.
The <info>sonata:page:create-site</info> command create a new site entity.

EOT
EOT
);
}

Expand Down Expand Up @@ -100,12 +100,12 @@ public function execute(InputInterface $input, OutputInterface $output)
$output->writeln(
<<<INFO
Creating website with the following information :
<info>name</info> : {$site->getName()}
<info>site</info> : http(s)://{$site->getHost()}{$site->getRelativePath()}
<info>enabled</info> : <info>from</info> {$info_enabledFrom} => <info>to</info> {$info_enabledTo}
Creating website with the following information :
<info>name</info> : {$site->getName()}
<info>site</info> : http(s)://{$site->getHost()}{$site->getRelativePath()}
<info>enabled</info> : <info>from</info> {$info_enabledFrom} => <info>to</info> {$info_enabledTo}
INFO
INFO
);

$confirmation = true;
Expand Down
14 changes: 7 additions & 7 deletions src/Command/CreateSnapshotsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreateSnapshotsCommand extends BaseCommand
*/
public function __construct($createSnapshot = null)
{
//NEXT_MAJOR: Remove the "if" condition and let only the "else" code.
// NEXT_MAJOR: Remove the "if" condition and let only the "else" code.
if (\is_string($createSnapshot) || null === $createSnapshot) {
@trigger_error(sprintf(
'The %s class is final since sonata-project/page-bundle 3.27.0 and and it will be removed in 4.0'
Expand All @@ -60,32 +60,32 @@ public function configure()
{
$this->setDescription('Create a snapshots of all pages available');
$this->addOption('site', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Site id');
//NEXT_MAJOR: Remove the "base-console" option.
// NEXT_MAJOR: Remove the "base-console" option.
$this->addOption('base-console', null, InputOption::VALUE_OPTIONAL, 'Base symfony console command', 'php app/console');
//NEXT_MAJOR: Remove the "mode" option.
// NEXT_MAJOR: Remove the "mode" option.
$this->addOption('mode', null, InputOption::VALUE_OPTIONAL, 'Run the command asynchronously', 'sync');
}

public function execute(InputInterface $input, OutputInterface $output)
{
$siteOption = $input->getOption('site');

//NEXT_MAJOR: Remove this condition.
// NEXT_MAJOR: Remove this condition.
if ('php app/console' !== $input->getOption('base-console')) {
@trigger_error(
'The "base-console" is deprecated since sonata-project/page-bundle 3.27.0 and will be removed in 4.0',
\E_USER_DEPRECATED
);
}

//NEXT_MAJOR: Remove this condition, because site will be optional
// NEXT_MAJOR: Remove this condition, because site will be optional
if ([] === $siteOption) {
$output->writeln('Please provide an <info>--site=SITE_ID</info> option or the <info>--site=all</info> directive');

return 1;
}

//NEXT_MAJOR: Remove this block condition.
// NEXT_MAJOR: Remove this block condition.
if (['all'] === $siteOption) {
@trigger_error(
sprintf(
Expand Down Expand Up @@ -138,7 +138,7 @@ public function execute(InputInterface $input, OutputInterface $output)
*/
protected function getSites($ids): array
{
//NEXT_MAJOR: Inject this on the __construct.
// NEXT_MAJOR: Inject this on the __construct.
$siteManager = $this->getContainer()->get('sonata.page.manager.site');

if ([] === $ids) {
Expand Down
12 changes: 6 additions & 6 deletions src/Command/DumpPageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function configure()
$this->setDescription('Dump page information');
$this->setHelp(
<<<HELP
Dump page information
Dump page information
Available managers:
- sonata.page.cms.snapshot
- sonata.page.cms.page
Available managers:
- sonata.page.cms.snapshot
- sonata.page.cms.page
You can use the --extended option to dump block configuration
HELP
You can use the --extended option to dump block configuration
HELP
);

$this->addArgument('manager', InputArgument::REQUIRED, 'The manager service id');
Expand Down
10 changes: 5 additions & 5 deletions src/Command/RenderBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function configure()
$this->setDescription('Dump page information');
$this->setHelp(
<<<HELP
Dump page information
Dump page information
Available manager:
- sonata.page.cms.snapshot
- sonata.page.cms.page
HELP
Available manager:
- sonata.page.cms.snapshot
- sonata.page.cms.page
HELP
);

$this->addArgument('manager', InputArgument::REQUIRED, 'The manager service id');
Expand Down
6 changes: 3 additions & 3 deletions src/Command/UpdateCoreRoutesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public function execute(InputInterface $input, OutputInterface $output)

$siteOption = $input->getOption('site');

//NEXT_MAJOR: Remove this condition, because site will be optional
// NEXT_MAJOR: Remove this condition, because site will be optional
if ([] === $siteOption) {
$output->writeln('Please provide an <info>--site=SITE_ID</info> option or the <info>--site=all</info> directive');

return 1;
}

//NEXT_MAJOR: Remove this block condition.
// NEXT_MAJOR: Remove this block condition.
if (['all'] === $siteOption) {
@trigger_error(
sprintf(
Expand Down Expand Up @@ -108,7 +108,7 @@ public function execute(InputInterface $input, OutputInterface $output)
*/
protected function getSites($ids): array
{
//NEXT_MAJOR: Inject this on the __construct.
// NEXT_MAJOR: Inject this on the __construct.
$siteManager = $this->getContainer()->get('sonata.page.manager.site');

if ([] === $ids) {
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/PageAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public function batchActionSnapshot($query)
}

foreach ($query->execute() as $page) {
//NEXT_MAJOR: Remove the $notificationBackend variable
// NEXT_MAJOR: Remove the $notificationBackend variable
$notificationBackend = $this->get('sonata.notification.backend');

//NEXT_MAJOR: Remove the "if" condition and use only "createByPage"
// NEXT_MAJOR: Remove the "if" condition and use only "createByPage"
if ($notificationBackend instanceof RuntimeBackend) {
//NEXT_MAJOR: Inject CreateSnapshotByPageInterface type and remove this "get" call.
// NEXT_MAJOR: Inject CreateSnapshotByPageInterface type and remove this "get" call.
$this->get('sonata.page.service.create_snapshot')->createByPage($page);
} else {
@trigger_error(
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/SiteAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ public function snapshotsAction()
$this->admin->setSubject($object);

if ('POST' === $request->getMethod()) {

//NEXT_MAJOR: remove notificationBackend and else block.
// NEXT_MAJOR: remove notificationBackend and else block.
$notificationBacked = $this->get('sonata.notification.backend');

if ($notificationBacked instanceof RuntimeBackend) {
//NEXT_MAJOR: inject CreateSnapshotBySiteInterface and remove this get.
// NEXT_MAJOR: inject CreateSnapshotBySiteInterface and remove this get.
$createSnapshot = $this->get('sonata.page.service.create_snapshot');
$createSnapshot->createBySite($object);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SnapshotAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function createAction(?Request $request = null)
$form->submit($request->request->get($form->getName()));

if ($form->isValid()) {
//@NEXT_MAJOR: when you're going to inject this service use CreateSnapshotByPageInterface
// @NEXT_MAJOR: when you're going to inject this service use CreateSnapshotByPageInterface
$createSnapshot = $this->get('sonata.page.service.create_snapshot');
$snapshot = $createSnapshot->createByPage($page);

Expand Down
Loading

0 comments on commit dff04de

Please sign in to comment.