Skip to content

Commit

Permalink
feat: update ECS config and apply standards
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine committed Jan 26, 2024
1 parent 7992eee commit 77bdbdb
Show file tree
Hide file tree
Showing 58 changed files with 187 additions and 208 deletions.
37 changes: 20 additions & 17 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,38 @@
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([__DIR__ . '/src', __DIR__ . '/tests', 'ecs.php']);

$ecsConfig->skip([
return ECSConfig::configure()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests', 'ecs.php'])
->withSkip([
NotOperatorWithSuccessorSpaceFixer::class,

Check failure on line 15 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer not found.
]);

$ecsConfig->sets([SetList::PSR_12, SetList::ARRAY, SetList::SPACES, SetList::NAMESPACES]);

])
/**
* Import
* @see https://cs.symfony.com/doc/rules/index.html#import
*/
$ecsConfig->rule(FullyQualifiedStrictTypesFixer::class);
$ecsConfig->rule(NoLeadingImportSlashFixer::class);
$ecsConfig->rule(SingleImportPerStatementFixer::class);
$ecsConfig->ruleWithConfiguration(GlobalNamespaceImportFixer::class, [
->withRules([
FullyQualifiedStrictTypesFixer::class,

Check failure on line 22 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer not found.
NoLeadingImportSlashFixer::class,

Check failure on line 23 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer not found.
SingleImportPerStatementFixer::class,

Check failure on line 24 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer not found.
])
->withConfiguredRule(GlobalNamespaceImportFixer::class, [

Check failure on line 26 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer not found.
'import_classes' => true,
]);

])
/**
* NativeFunctionInvocation
* @see https://cs.symfony.com/doc/rules/function_notation/native_function_invocation.html
*/
$ecsConfig->ruleWithConfiguration(NativeFunctionInvocationFixer::class, [
->withConfiguredRule(NativeFunctionInvocationFixer::class, [

Check failure on line 33 in ecs.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

Class PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer not found.
'include' => [
'@all',
],
'scope' => 'namespaced',
'strict' => true,
]);
};
])
->withSets([
SetList::PSR_12,
SetList::ARRAY,
SetList::SPACES,
SetList::NAMESPACES,
])
;
5 changes: 2 additions & 3 deletions src/AccessesPostsLazily.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Timber;

use ReturnTypeWillChange;

use Timber\Factory\PostFactory;
use WP_Post;

Expand All @@ -25,7 +24,7 @@ trait AccessesPostsLazily
/**
* PostFactory instance used internally to instantiate Posts.
*
* @var \Timber\Factory\PostFactory
* @var PostFactory
*/
private $factory;

Expand Down Expand Up @@ -67,7 +66,7 @@ trait AccessesPostsLazily
* // No additional overhead here.
* }
* ```
* @return \Timber\PostCollectionInterface The realized PostQuery.
* @return PostCollectionInterface The realized PostQuery.
*/
public function realize(): self

Check failure on line 71 in src/AccessesPostsLazily.php

View workflow job for this annotation

GitHub Actions / PHP static analysis

PHPDoc tag @return with type Timber\PostCollectionInterface is not subtype of native type Timber\PostQuery.
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/WPObjectCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class WPObjectCacheAdapter
private $cache_group;

/**
* @var \Timber\Loader
* @var Loader
*/
private $timberloader;

Expand Down
2 changes: 1 addition & 1 deletion src/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function children()
* Adds a child.
*
* @api
* @param \Timber\Comment $child_comment Comment child to add.
* @param Comment $child_comment Comment child to add.
* @return array Comment children.
*/
public function add_child(Comment $child_comment)
Expand Down
2 changes: 1 addition & 1 deletion src/CoreEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
* @param string $post_meta The field value.
* @param int $post_id The post ID.
* @param string $field_name The name of the meta field to get the value for.
* @param \Timber\CoreEntity $post The post object.
* @param CoreEntity $post The post object.
* @param array $args An array of arguments.
*/
$object_meta = \apply_filters(
Expand Down
1 change: 0 additions & 1 deletion src/Factory/CommentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use InvalidArgumentException;
use Timber\Comment;

use Timber\CoreInterface;
use WP_Comment;
use WP_Comment_Query;
Expand Down
1 change: 0 additions & 1 deletion src/Factory/MenuItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Timber\Factory;

use Timber\CoreInterface;

use Timber\Menu;
use Timber\MenuItem;
use WP_Post;
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/PagesMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PagesMenuFactory
*
* @param array $args Optional. Args for get_pages().
*
* @return \Timber\CoreInterface
* @return CoreInterface
*/
public function from_pages(array $args = [])
{
Expand Down
1 change: 0 additions & 1 deletion src/Factory/PostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Timber\PathHelper;
use Timber\Post;
use Timber\PostArrayObject;

use Timber\PostQuery;
use WP_Post;
use WP_Query;
Expand Down
1 change: 0 additions & 1 deletion src/Factory/TermFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use InvalidArgumentException;
use Timber\CoreInterface;

use Timber\Term;
use WP_Term;
use WP_Term_Query;
Expand Down
1 change: 0 additions & 1 deletion src/Factory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use InvalidArgumentException;
use Timber\CoreInterface;

use Timber\User;
use WP_User;
use WP_User_Query;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static function _delete_generated_if_image($post_id)
{
if (\wp_attachment_is_image($post_id)) {
$attachment = Timber::get_post($post_id);
/** @var \Timber\Attachment $attachment */
/** @var Attachment $attachment */
if ($file_loc = $attachment->file_loc()) {
ImageHelper::delete_generated_files($file_loc);
}
Expand Down
1 change: 0 additions & 1 deletion src/Integration/AcfIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Timber\Integration;

use ACF;

use DateTimeImmutable;
use Timber\Timber;

Expand Down
2 changes: 1 addition & 1 deletion src/Integration/CoAuthorsPlus/CoAuthorsPlusUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function from_guest_author(stdclass $coauthor)
protected function init($coauthor = false)
{
/**
* @var stdClass $coauthor
* @var stdclass $coauthor
*/
parent::init($coauthor);

Expand Down
1 change: 0 additions & 1 deletion src/Integration/CoAuthorsPlusIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CoAuthors_Plus;
use Timber\Integration\CoAuthorsPlus\CoAuthorsPlusUser;

use WP_User;

class CoAuthorsPlusIntegration implements IntegrationInterface
Expand Down
16 changes: 8 additions & 8 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function choose_template($templates)
}

/**
* @return \Twig\Loader\FilesystemLoader
* @return FilesystemLoader
*/
public function get_loader()
{
Expand Down Expand Up @@ -308,7 +308,7 @@ public function get_loader()
}

/**
* @return \Twig\Environment
* @return Environment
*/
public function get_twig()
{
Expand Down Expand Up @@ -432,7 +432,7 @@ public function get_twig()

$environment_options['cache'] = $twig_cache_loc;
}
$twig = new \Twig\Environment($this->get_loader(), $environment_options);
$twig = new Environment($this->get_loader(), $environment_options);

if (WP_DEBUG) {
$twig->addExtension(new \Twig\Extension\DebugExtension());
Expand Down Expand Up @@ -463,7 +463,7 @@ public function get_twig()
*
* @since 0.20.10
*
* @param \Twig\Environment $twig The Twig environment you can add functionality to.
* @param Environment $twig The Twig environment you can add functionality to.
*/
$twig = \apply_filters('timber/loader/twig', $twig);

Expand Down Expand Up @@ -502,7 +502,7 @@ public function get_twig()
* </a>
* ```
*
* @param \Twig\Environment $twig The Twig environment.
* @param Environment $twig The Twig environment.
*/
$twig = \apply_filters('timber/twig', $twig);

Expand Down Expand Up @@ -628,12 +628,12 @@ public static function rrmdir($dirPath)
}

/**
* @return \Twig\CacheExtension\Extension
* @return CacheExtension\Extension
*/
private function _get_cache_extension()
{
$key_generator = new \Timber\Cache\KeyGenerator();
$cache_provider = new \Timber\Cache\WPObjectCacheAdapter($this);
$key_generator = new Cache\KeyGenerator();
$cache_provider = new Cache\WPObjectCacheAdapter($this);
$cache_lifetime = \apply_filters('timber/cache/extension/lifetime', 0);
$cache_strategy = new CacheExtension\CacheStrategy\GenerationalCacheStrategy(
$cache_provider,
Expand Down
7 changes: 3 additions & 4 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Timber;

use Throwable;

use Timber\Factory\MenuItemFactory;
use WP_Term;

Expand Down Expand Up @@ -117,7 +116,7 @@ class Menu extends CoreEntity
* @param array $args Optional. Right now, only the `depth` is
* supported which says how many levels of hierarchy should be
* included in the menu. Default `0`, which is all levels.
* @return \Timber\Menu
* @return Menu
*/
public static function build(?WP_Term $menu, $args = []): ?self
{
Expand Down Expand Up @@ -278,7 +277,7 @@ public static function build(?WP_Term $menu, $args = []): ?self
* many levels of hierarchy should be included in the menu. Default
* `0`, which is all levels.
*/
protected function __construct(?WP_term $term, array $args = [])
protected function __construct(?WP_Term $term, array $args = [])
{
// For future enhancements?
$this->raw_args = $args;
Expand Down Expand Up @@ -340,7 +339,7 @@ protected function convert_menu_items(array $menu_items): array
* @api
* @param array $menu_items An array of menu items.
* @param int $parent_id The parent ID to look for.
* @return \Timber\MenuItem|null A menu item. False if no parent was found.
* @return MenuItem|null A menu item. False if no parent was found.
*/
public function find_parent_item_in_menu(array $menu_items, int $parent_id): ?MenuItem
{
Expand Down
12 changes: 6 additions & 6 deletions src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MenuItem extends CoreEntity
*
* @since 1.12.0
* @see \Timber\MenuItem::menu()
* @var \Timber\Menu The `Timber\Menu` object the menu item is associated with.
* @var Menu The `Timber\Menu` object the menu item is associated with.
*/
protected $menu;

Expand Down Expand Up @@ -119,8 +119,8 @@ class MenuItem extends CoreEntity
/**
* @internal
* @param array|object $data The data this MenuItem is wrapping
* @param \Timber\Menu $menu The `Timber\Menu` object the menu item is associated with.
* @return \Timber\MenuItem a new MenuItem instance
* @param Menu $menu The `Timber\Menu` object the menu item is associated with.
* @return MenuItem a new MenuItem instance
*/
public static function build($data, ?Menu $menu = null): self
{
Expand All @@ -130,7 +130,7 @@ public static function build($data, ?Menu $menu = null): self
/**
* @internal
* @param WP_Post $data
* @param \Timber\Menu $menu The `Timber\Menu` object the menu item is associated with.
* @param Menu $menu The `Timber\Menu` object the menu item is associated with.
*/
protected function __construct(WP_Post $data, $menu = null)
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public function master_object()
*
* @api
*
* @param \Timber\MenuItem $item The menu item to add.
* @param MenuItem $item The menu item to add.
*/
public function add_child(MenuItem $item)
{
Expand Down Expand Up @@ -479,7 +479,7 @@ public function target()
*
* @api
* @since 1.12.0
* @return \Timber\Menu The `Timber\Menu` object the menu item is associated with.
* @return Menu The `Timber\Menu` object the menu item is associated with.
*/
public function menu()
{
Expand Down
2 changes: 1 addition & 1 deletion src/PagesMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PagesMenu extends Menu
* @param null $menu Unused. Only here for compatibility with the Timber\Menu class.
* @param array $args Optional. Args for wp_list_pages().
*
* @return \Timber\PagesMenu
* @return PagesMenu
*/
public static function build($menu, $args = []): ?self
{
Expand Down

0 comments on commit 77bdbdb

Please sign in to comment.