diff --git a/composer.json b/composer.json index 17d4760..4b86131 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,10 @@ "ext-fileinfo" : "*", "ext-session": "*", "oscarotero/env": "^2.1", - "symfony/templating": "^4.0|^5.0", - "symfony/twig-bundle": "^4.0|^5.0", - "symfony/asset": "^4.0|^5.0", - "symfony/http-client": "^4.0|^5.0", + "symfony/templating": "^4.0|^5.0|^6.0|^7.0", + "symfony/twig-bundle": "^4.0|^5.0|^6.0|^7.0", + "symfony/asset": "^4.0|^5.0|^6.0|^7.0", + "symfony/http-client": "^4.0|^5.0|^6.0|^7.0", "metabolism/wordpress-core-installer": "^1.0", "metabolism/package-actions": "^1.0", "metabolism/wp-steroids": "^1.3.0", @@ -109,5 +109,8 @@ "metabolism/package-actions": true, "metabolism/wordpress-core-installer": true } + }, + "require-dev": { + "rector/rector": "^2.0" } } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..a28172c --- /dev/null +++ b/rector.php @@ -0,0 +1,32 @@ +withPaths([ + __DIR__ . '/config', + __DIR__ . '/samples/public', + __DIR__ . '/samples/src', + __DIR__ . '/src', + ]) + ->withPreparedSets(symfonyConfigs: true) + ->withComposerBased(twig: true, doctrine: true) + //->withPhpSets() + //->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml') + ->withSets([ + //SymfonySetList::SYMFONY_73, + //SymfonySetList::SYMFONY_74, + //SymfonySetList::SYMFONY_CODE_QUALITY, + //SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, + ]) + ->withSkip([ + AddClosureVoidReturnTypeWhereNoReturnRector::class + ]) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0) +; diff --git a/samples/src/Twig/AppExtension.php b/samples/src/Twig/AppExtension.php index 4dc4713..6d8ef78 100644 --- a/samples/src/Twig/AppExtension.php +++ b/samples/src/Twig/AppExtension.php @@ -22,20 +22,20 @@ class AppExtension extends AbstractExtension{ public function getFilters() { return [ - new TwigFilter( 'clean_id', [$this,'cleanID'] ), - new TwigFilter( 'format_number', [$this,'formatNumber'] ), - new TwigFilter( 'll_CC', [$this,'llCC'] ), - new TwigFilter( 'br_to_space', [$this,'brToSpace'] ), - new TwigFilter( 'remove_accent', [$this,'removeAccent'] ), - new TwigFilter( 'typeOf', [$this,'typeOf'] ), - new TwigFilter( 'bind', [$this,'bind'] ), - new TwigFilter( 'implode', [$this,'implode'] ), - new TwigFilter( 'striptag', [$this, 'striptag']), - new TwigFilter( 'br_to_line', [$this, 'brToLine']), - new TwigFilter( 'remove_br', [$this, 'removeBr']), - new TwigFilter( 'file_content', [$this, 'getFileContent']), - new TwigFilter( 'wrap_embed', [$this, 'wrapEmbed']), - new TwigFilter( 'truncate', [$this, 'truncate']) ]; + new TwigFilter( 'clean_id', $this->cleanID(...) ), + new TwigFilter( 'format_number', $this->formatNumber(...) ), + new TwigFilter( 'll_CC', $this->llCC(...) ), + new TwigFilter( 'br_to_space', $this->brToSpace(...) ), + new TwigFilter( 'remove_accent', $this->removeAccent(...) ), + new TwigFilter( 'typeOf', $this->typeOf(...) ), + new TwigFilter( 'bind', $this->bind(...) ), + new TwigFilter( 'implode', $this->implode(...) ), + new TwigFilter( 'striptag', $this->striptag(...)), + new TwigFilter( 'br_to_line', $this->brToLine(...)), + new TwigFilter( 'remove_br', $this->removeBr(...)), + new TwigFilter( 'file_content', $this->getFileContent(...)), + new TwigFilter( 'wrap_embed', $this->wrapEmbed(...)), + new TwigFilter( 'truncate', $this->truncate(...)) ]; } /** @@ -44,7 +44,7 @@ public function getFilters() public function getFunctions() { return [ - new TwigFunction( 'blank', [$this,'blank'] ) + new TwigFunction( 'blank', $this->blank(...) ) ]; } diff --git a/samples/src/Twig/TwigGlobalSubscriber.php b/samples/src/Twig/TwigGlobalSubscriber.php index 8c5774d..38790fa 100644 --- a/samples/src/Twig/TwigGlobalSubscriber.php +++ b/samples/src/Twig/TwigGlobalSubscriber.php @@ -27,7 +27,7 @@ public function injectGlobalVariables( ControllerEvent $event ) { $this->twig->addGlobal( 'subsidiaries', $subsidiaries ); } - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'injectGlobalVariables' ]; } } \ No newline at end of file diff --git a/src/ArgumentResolver/BCValueResolverInterface.php b/src/ArgumentResolver/BCValueResolverInterface.php new file mode 100644 index 0000000..e4bb829 --- /dev/null +++ b/src/ArgumentResolver/BCValueResolverInterface.php @@ -0,0 +1,23 @@ +supports($request, $argument)) { + return []; + } + yield Blog::getInstance(); } } diff --git a/src/ArgumentResolver/PostCollectionValueResolver.php b/src/ArgumentResolver/PostCollectionValueResolver.php index 03834fd..823e50f 100644 --- a/src/ArgumentResolver/PostCollectionValueResolver.php +++ b/src/ArgumentResolver/PostCollectionValueResolver.php @@ -4,14 +4,13 @@ use Metabolism\WordpressBundle\Entity\PostCollection; use Metabolism\WordpressBundle\Repository\PostRepository; -use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; /** * Class Metabolism\WordpressBundle Framework */ -class PostCollectionValueResolver implements ArgumentValueResolverInterface { +class PostCollectionValueResolver implements BCValueResolverInterface { private $postRepository; @@ -41,6 +40,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool */ public function resolve(Request $request, ArgumentMetadata $argument): iterable { + if (!$this->supports($request, $argument)) { + return []; + } + yield $this->postRepository->findQueried($argument->isNullable()); } } diff --git a/src/ArgumentResolver/PostValueResolver.php b/src/ArgumentResolver/PostValueResolver.php index 9eca370..9defb0f 100644 --- a/src/ArgumentResolver/PostValueResolver.php +++ b/src/ArgumentResolver/PostValueResolver.php @@ -4,14 +4,13 @@ use Metabolism\WordpressBundle\Entity\Post; use Metabolism\WordpressBundle\Repository\PostRepository; -use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; /** * Class Metabolism\WordpressBundle Framework */ -class PostValueResolver implements ArgumentValueResolverInterface { +class PostValueResolver implements BCValueResolverInterface { private $postRepository; @@ -44,6 +43,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool */ public function resolve(Request $request, ArgumentMetadata $argument): iterable { + if (!$this->supports($request, $argument)) { + return []; + } + yield $this->postRepository->findQueried($argument->isNullable()); } } diff --git a/src/ArgumentResolver/TermValueResolver.php b/src/ArgumentResolver/TermValueResolver.php index 08d15b9..72c4c88 100644 --- a/src/ArgumentResolver/TermValueResolver.php +++ b/src/ArgumentResolver/TermValueResolver.php @@ -4,14 +4,13 @@ use Metabolism\WordpressBundle\Entity\Term; use Metabolism\WordpressBundle\Repository\TermRepository; -use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; /** * Class Metabolism\WordpressBundle Framework */ -class TermValueResolver implements ArgumentValueResolverInterface { +class TermValueResolver implements BCValueResolverInterface { private $termRepository; @@ -41,6 +40,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool */ public function resolve(Request $request, ArgumentMetadata $argument): iterable { + if (!$this->supports($request, $argument)) { + return []; + } + yield $this->termRepository->findQueried($argument->isNullable()); } } diff --git a/src/ArgumentResolver/UserValueResolver.php b/src/ArgumentResolver/UserValueResolver.php index 8a73589..ed50fdb 100644 --- a/src/ArgumentResolver/UserValueResolver.php +++ b/src/ArgumentResolver/UserValueResolver.php @@ -11,7 +11,7 @@ /** * Class Metabolism\WordpressBundle Framework */ -class UserValueResolver implements ArgumentValueResolverInterface { +class UserValueResolver implements BCValueResolverInterface { private $userRepository; @@ -41,6 +41,10 @@ public function supports(Request $request, ArgumentMetadata $argument): bool */ public function resolve(Request $request, ArgumentMetadata $argument): iterable { + if (!$this->supports($request, $argument)) { + return []; + } + yield $this->userRepository->findQueried($argument->isNullable()); } } diff --git a/src/DependencyInjection/WordpressExtension.php b/src/DependencyInjection/WordpressExtension.php index 00cd75e..20b02f9 100644 --- a/src/DependencyInjection/WordpressExtension.php +++ b/src/DependencyInjection/WordpressExtension.php @@ -6,7 +6,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Extension\Extension; /** * Class Metabolism\WordpressBundle Framework @@ -33,12 +33,4 @@ public function prepend(ContainerBuilder $container) { // TODO: Implement prepend() method. } - - /** - * @return string - */ - public function getAlias() - { - return parent::getAlias(); - } } diff --git a/src/EventSubscriber/KernelEventsSubscriber.php b/src/EventSubscriber/KernelEventsSubscriber.php index fb0be44..b1df2d2 100644 --- a/src/EventSubscriber/KernelEventsSubscriber.php +++ b/src/EventSubscriber/KernelEventsSubscriber.php @@ -15,7 +15,7 @@ class KernelEventsSubscriber implements EventSubscriberInterface /** * @return array */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'onKernelController', diff --git a/src/Twig/WordpressTwigExtension.php b/src/Twig/WordpressTwigExtension.php index 4d863d4..f20ccb8 100644 --- a/src/Twig/WordpressTwigExtension.php +++ b/src/Twig/WordpressTwigExtension.php @@ -29,23 +29,23 @@ public function getFilters(): array { return [ new TwigFilter( 'handle', 'sanitize_title' ), - new TwigFilter( 'placeholder', [$this, 'placeholder'] ), - new TwigFilter( 'more', [$this, 'more'] ), - new TwigFilter( 'resize', [$this, 'resize'] ), - new TwigFilter( 'picture', [$this, 'picture'] ), - new TwigFilter( 'blurhash', [$this, 'blurhash'] ), - new TwigFilter( 'figure', [$this, 'figure'] ), + new TwigFilter( 'placeholder', $this->placeholder(...) ), + new TwigFilter( 'more', $this->more(...) ), + new TwigFilter( 'resize', $this->resize(...) ), + new TwigFilter( 'picture', $this->picture(...) ), + new TwigFilter( 'blurhash', $this->blurhash(...) ), + new TwigFilter( 'figure', $this->figure(...) ), new TwigFilter( 'stripshortcodes','strip_shortcodes' ), new TwigFilter( 'trim_words','wp_trim_words' ), - new TwigFilter( 'function', [$this, 'execFunction'] ), + new TwigFilter( 'function', $this->execFunction(...) ), new TwigFilter( 'excerpt','wp_trim_words' ), new TwigFilter( 'sanitize','sanitize_title' ), new TwigFilter( 'base64_encode','base64_encode' ), new TwigFilter( 'base64_decode','base64_decode' ), - new TwigFilter( 'shortcodes', [$this, 'doShortcode'] ), + new TwigFilter( 'shortcodes', $this->doShortcode(...) ), new TwigFilter( 'wpautop','wpautop' ), - new TwigFilter( 'array',[$this, 'toArray'] ), - new TwigFilter( 'file_exists',[$this, 'fileExists'] ), + new TwigFilter( 'array',$this->toArray(...) ), + new TwigFilter( 'file_exists',$this->fileExists(...) ), ]; } @@ -57,20 +57,20 @@ public function getFunctions(): array $blog = Blog::getInstance(); return [ - new TwigFunction( 'placeholder', [$this, 'generatePlaceholder'] ), - new TwigFunction( 'pixel', [$this, 'generatePixel'] ), - new TwigFunction( 'fn', [$this, 'execFunction'] ), - new TwigFunction( 'function', [$this, 'execFunction'] ), - new TwigFunction( 'action', [$this, 'doAction'] ), + new TwigFunction( 'placeholder', $this->generatePlaceholder(...) ), + new TwigFunction( 'pixel', $this->generatePixel(...) ), + new TwigFunction( 'fn', $this->execFunction(...) ), + new TwigFunction( 'function', $this->execFunction(...) ), + new TwigFunction( 'action', $this->doAction(...) ), new TwigFunction( 'shortcode', 'do_shortcode' ), new TwigFunction( 'login_url', 'wp_login_url' ), new TwigFunction( 'home_url', 'get_home_url' ), new TwigFunction( 'search_form', 'get_search_form' ), - new TwigFunction( 'archive_url', [$blog, 'getArchiveLink'] ), - new TwigFunction( 'archive_title', [$blog, 'getArchiveTitle'] ), + new TwigFunction( 'archive_url', $blog->getArchiveLink(...) ), + new TwigFunction( 'archive_title', $blog->getArchiveTitle(...) ), new TwigFunction( 'attachment_url', 'wp_get_attachment_url' ), - new TwigFunction( 'post_url', [$this, 'getPermalink'] ), - new TwigFunction( 'term_url', [$this, 'getTermLink'] ), + new TwigFunction( 'post_url', $this->getPermalink(...) ), + new TwigFunction( 'term_url', $this->getTermLink(...) ), new TwigFunction( 'bloginfo', 'get_bloginfo' ), new TwigFunction( 'dynamic_sidebar', function($id){ return $this->getOutput('dynamic_sidebar', [$id]); }, ['is_safe' => array('html')] ), new TwigFunction( 'comment_form', function($post_id, $args=[]){ return $this->getOutput('comment_form', [$args, $post_id]); }, ['is_safe' => array('html')] ),