Autofix issues detected by CodeSniffer

[MAILPOET-4617]
This commit is contained in:
Jan Jakes
2022-09-06 16:49:20 +02:00
committed by Rostislav Wolný
parent a377f0c946
commit c601aaa3eb
29 changed files with 123 additions and 80 deletions

View File

@ -9,7 +9,6 @@ use MailPoet\Config\AccessControl;
use MailPoet\Newsletter\ApiDataSanitizer;
use MailPoet\NewsletterTemplates\NewsletterTemplatesRepository;
use MailPoet\NewsletterTemplates\ThumbnailSaver;
use MailPoet\WP\Functions as WPFunctions;
class NewsletterTemplates extends APIEndpoint {
public $permissions = [

View File

@ -5,7 +5,6 @@ namespace MailPoet\Automation\Engine\Builder;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Automation\Engine\Storage\WorkflowTemplateStorage;
use MailPoet\Automation\Integrations\MailPoet\Templates\WorkflowBuilder;
use MailPoet\UnexpectedValueException;
class CreateWorkflowFromTemplateController {
@ -26,7 +25,7 @@ class CreateWorkflowFromTemplateController {
public function createWorkflow(string $slug): Workflow {
$template = $this->templateStorage->getTemplateBySlug($slug);
if (! $template) {
if (!$template) {
throw UnexpectedValueException::create()->withMessage('Template not found.');
}

View File

@ -1,11 +1,11 @@
<?php
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Data;
use MailPoet\RuntimeException;
class WorkflowTemplate
{
class WorkflowTemplate {
public const CATEGORY_WELCOME = 1;
public const CATEGORY_ABANDONED_CART = 2;
@ -30,8 +30,13 @@ class WorkflowTemplate
/** @var Workflow */
private $workflow;
public function __construct(string $slug, int $category, string $description, Workflow $workflow) {
if (! in_array($category, self::ALL_CATEGORIES)) {
public function __construct(
string $slug,
int $category,
string $description,
Workflow $workflow
) {
if (!in_array($category, self::ALL_CATEGORIES)) {
throw new RuntimeException("$category is not a valid category.");
}
$this->slug = $slug;
@ -40,27 +45,27 @@ class WorkflowTemplate
$this->workflow = $workflow;
}
public function getSlug() : string {
public function getSlug(): string {
return $this->slug;
}
public function getName() : string {
public function getName(): string {
return $this->workflow->getName();
}
public function getCategory() : int {
public function getCategory(): int {
return $this->category;
}
public function getDescription() : string {
public function getDescription(): string {
return $this->description;
}
public function getWorkflow() : Workflow {
public function getWorkflow(): Workflow {
return $this->workflow;
}
public function toArray() : array {
public function toArray(): array {
return [
'slug' => $this->getSlug(),
'name' => $this->getName(),

View File

@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
@ -9,22 +9,25 @@ use MailPoet\Automation\Engine\Data\WorkflowTemplate;
use MailPoet\Automation\Engine\Storage\WorkflowTemplateStorage;
use MailPoet\Validator\Builder;
class WorkflowTemplatesGetEndpoint extends Endpoint
{
class WorkflowTemplatesGetEndpoint extends Endpoint {
private $storage;
public function __construct(WorkflowTemplateStorage $storage) {
public function __construct(
WorkflowTemplateStorage $storage
) {
$this->storage = $storage;
}
public function handle(Request $request): Response {
$templates = $this->storage->getTemplates((int) $request->getParam('category'));
$templates = $this->storage->getTemplates((int)$request->getParam('category'));
return new Response(array_map(function (WorkflowTemplate $workflow) {
return $workflow->toArray();
}, $templates));
}
public static function getRequestSchema() : array {
public static function getRequestSchema(): array {
return [
'category' => Builder::integer()->nullable(),
];

View File

@ -6,8 +6,6 @@ use MailPoet\Automation\Engine\API\Endpoint;
use MailPoet\Automation\Engine\API\Request;
use MailPoet\Automation\Engine\API\Response;
use MailPoet\Automation\Engine\Builder\CreateWorkflowFromTemplateController;
use MailPoet\RuntimeException;
use MailPoet\UnexpectedValueException;
use MailPoet\Validator\Builder;
class WorkflowsCreateFromTemplateEndpoint extends Endpoint {

View File

@ -1,17 +1,14 @@
<?php
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Storage;
use MailPoet\Automation\Engine\Data\WorkflowTemplate;
use MailPoet\Automation\Engine\Hooks;
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
use MailPoet\Automation\Integrations\MailPoet\Actions\SendEmailAction;
use MailPoet\Automation\Integrations\MailPoet\Templates\WorkflowBuilder;
use MailPoet\Automation\Integrations\MailPoet\Triggers\SegmentSubscribedTrigger;
use MailPoet\WP\Functions as WPFunctions;
class WorkflowTemplateStorage
{
class WorkflowTemplateStorage {
/** @var WorkflowTemplate[] */
private $templates = [];
@ -22,13 +19,16 @@ class WorkflowTemplateStorage
/** @var WPFunctions */
private $wp;
public function __construct(WorkflowBuilder $builder, WPFunctions $wp) {
public function __construct(
WorkflowBuilder $builder,
WPFunctions $wp
) {
$this->builder = $builder;
$this->wp = $wp;
$this->templates = $this->createTemplates();
}
public function getTemplateBySlug(string $slug) : ?WorkflowTemplate {
public function getTemplateBySlug(string $slug): ?WorkflowTemplate {
foreach ($this->templates as $template) {
if ($template->getSlug() === $slug) {
return $template;
@ -38,21 +38,21 @@ class WorkflowTemplateStorage
}
/** @return WorkflowTemplate[] */
public function getTemplates(int $category = null) : array {
if (! $category) {
public function getTemplates(int $category = null): array {
if (!$category) {
return $this->templates;
}
return array_values(
array_filter(
$this->templates,
function(WorkflowTemplate $template) use ($category) : bool {
function(WorkflowTemplate $template) use ($category): bool {
return $template->getCategory() === $category;
}
)
);
}
private function createTemplates() : array {
private function createTemplates(): array {
$simpleWelcomeEmail = new WorkflowTemplate(
'simple-welcome-email',
WorkflowTemplate::CATEGORY_WELCOME,
@ -67,9 +67,9 @@ class WorkflowTemplateStorage
)
);
$templates = $this->wp->applyFilters(Hooks::WORKFLOW_TEMPLATES,[
$templates = $this->wp->applyFilters(Hooks::WORKFLOW_TEMPLATES, [
$simpleWelcomeEmail,
]);
return is_array($templates)?$templates:[];
return is_array($templates) ? $templates : [];
}
}

View File

@ -1,15 +1,11 @@
<?php declare(strict_types=1);
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Integrations\MailPoet\Templates;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Data\WorkflowTemplate;
use MailPoet\Automation\Engine\Registry;
use MailPoet\Automation\Engine\Workflows\Trigger;
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
use MailPoet\Automation\Integrations\MailPoet\Actions\SendEmailAction;
use MailPoet\Automation\Integrations\MailPoet\Triggers\SegmentSubscribedTrigger;
use MailPoet\Util\Security;
use MailPoet\Validator\Schema\ObjectSchema;
@ -18,22 +14,24 @@ class WorkflowBuilder {
/** @var Registry */
private $registry;
public function __construct(Registry $registry) {
public function __construct(
Registry $registry
) {
$this->registry = $registry;
}
public function createFromSequence(string $name, array $sequence, array $sequenceArgs = []) : Workflow {
public function createFromSequence(string $name, array $sequence, array $sequenceArgs = []): Workflow {
$steps = [];
$nextStep = null;
foreach (array_reverse($sequence) as $index => $stepKey) {
$workflowStep = $this->registry->getStep($stepKey);
if (! $workflowStep) {
if (!$workflowStep) {
continue;
}
$args = array_merge($this->getDefaultArgs($workflowStep->getArgsSchema()), array_reverse($sequenceArgs)[$index] ?? []);
$step = new Step(
$this->uniqueId(),
in_array(Trigger::class, (array) class_implements($workflowStep)) ? Step::TYPE_TRIGGER : Step::TYPE_ACTION,
in_array(Trigger::class, (array)class_implements($workflowStep)) ? Step::TYPE_TRIGGER : Step::TYPE_ACTION,
$stepKey,
$nextStep,
$args
@ -53,7 +51,6 @@ class WorkflowBuilder {
return Security::generateRandomString(16);
}
private function getDefaultArgs(ObjectSchema $argsSchema): array {
$args = [];
foreach ($argsSchema->toArray()['properties'] ?? [] as $name => $schema) {

View File

@ -12,14 +12,17 @@ class AssetsLoader {
/** @var WPFunctions */
private $wp;
public function __construct(RendererFactory $rendererFactory, WPFunctions $wp) {
public function __construct(
RendererFactory $rendererFactory,
WPFunctions $wp
) {
$this->renderer = $rendererFactory->getRenderer();
$this->wp = $wp;
}
public function loadStyles(): void {
// MailPoet plugin style should be loaded on all mailpoet sites
if (isset($_GET['page']) && strpos($_GET['page'], 'mailpoet-') === 0 ) {
if (isset($_GET['page']) && strpos($_GET['page'], 'mailpoet-') === 0) {
$this->enqueueStyle('mailpoet-plugin', [
'forms', // To prevent conflict in CSS with WP forms we need to add dependency
'buttons',

View File

@ -9,8 +9,8 @@ use MailPoetVendor\Doctrine\Common\Cache\CacheProvider;
* Based on https://github.com/doctrine/cache/blob/1.11.x/lib/Doctrine/Common/Cache/ArrayCache.php
* The cache implementation was removed from the doctrine/cache v2.0 so we need to provide own implementation.
*/
class ArrayCache extends CacheProvider
{
class ArrayCache extends CacheProvider {
/** @var mixed[] */
private $data = [];
@ -26,8 +26,7 @@ class ArrayCache extends CacheProvider
/**
* {@inheritdoc}
*/
public function __construct()
{
public function __construct() {
$this->upTime = time();
}
@ -35,7 +34,7 @@ class ArrayCache extends CacheProvider
* {@inheritdoc}
*/
protected function doFetch($id) {
if (! $this->doContains($id)) {
if (!$this->doContains($id)) {
$this->missesCount += 1;
return false;
}
@ -47,7 +46,7 @@ class ArrayCache extends CacheProvider
* {@inheritdoc}
*/
protected function doContains($id) {
if (! isset($this->data[$id])) {
if (!isset($this->data[$id])) {
return false;
}
$expiration = $this->data[$id][1];
@ -87,10 +86,10 @@ class ArrayCache extends CacheProvider
*/
protected function doGetStats() {
return [
CacheProvider::STATS_HITS => $this->hitsCount,
CacheProvider::STATS_MISSES => $this->missesCount,
CacheProvider::STATS_UPTIME => $this->upTime,
CacheProvider::STATS_MEMORY_USAGE => null,
CacheProvider::STATS_HITS => $this->hitsCount,
CacheProvider::STATS_MISSES => $this->missesCount,
CacheProvider::STATS_UPTIME => $this->upTime,
CacheProvider::STATS_MEMORY_USAGE => null,
CacheProvider::STATS_MEMORY_AVAILABLE => null,
];
}

View File

@ -49,7 +49,7 @@ class CacheOnlyMappingDriver implements MappingDriver {
/**
* Copy pasted from MailPoetVendor\Doctrine\Persistence\Mapping\AbstractClassMetadataFactory
*/
protected function getCacheKey(string $className) : string {
protected function getCacheKey(string $className): string {
return str_replace('\\', '__', $className) . $this->cacheSalt;
}
}

View File

@ -20,7 +20,10 @@ class ConfigurationFactory {
/** @var AnnotationReaderProvider */
private $annotationReaderProvider;
public function __construct(AnnotationReaderProvider $annotationReaderProvider, $isDevMode = null) {
public function __construct(
AnnotationReaderProvider $annotationReaderProvider,
$isDevMode = null
) {
$this->isDevMode = $isDevMode === null ? WP_DEBUG : $isDevMode;
$this->annotationReaderProvider = $annotationReaderProvider;
}

View File

@ -4,12 +4,12 @@ namespace MailPoet\Doctrine;
use MailPoet\Config\Env;
use MailPoet\Doctrine\Types\BigIntType;
use MailPoet\Doctrine\Types\DateTimeTzToStringType;
use MailPoet\Doctrine\Types\JsonOrSerializedType;
use MailPoet\Doctrine\Types\JsonType;
use MailPoet\Doctrine\Types\SerializedArrayType;
use MailPoet\Doctrine\Types\DateTimeTzToStringType;
use MailPoetVendor\Doctrine\DBAL\DriverManager;
use MailPoetVendor\Doctrine\DBAL\Driver\PDO\MySQL\Driver;
use MailPoetVendor\Doctrine\DBAL\DriverManager;
use MailPoetVendor\Doctrine\DBAL\Platforms\MySqlPlatform;
use MailPoetVendor\Doctrine\DBAL\Types\Type;
use PDO;

View File

@ -10,7 +10,9 @@ class EmojiEncodingListener {
/** @var Emoji */
private $emoji;
public function __construct(Emoji $emoji) {
public function __construct(
Emoji $emoji
) {
$this->emoji = $emoji;
}

View File

@ -11,7 +11,9 @@ class LastSubscribedAtListener {
/** @var Carbon */
private $now;
public function __construct(WPFunctions $wp) {
public function __construct(
WPFunctions $wp
) {
$this->now = Carbon::createFromTimestamp($wp->currentTime('timestamp'));
}

View File

@ -13,7 +13,9 @@ class TimestampListener {
/** @var Carbon */
private $now;
public function __construct(WPFunctions $wp) {
public function __construct(
WPFunctions $wp
) {
$this->now = Carbon::createFromTimestamp($wp->currentTime('timestamp'));
}

View File

@ -10,7 +10,9 @@ class ValidationListener {
/** @var ValidatorInterface */
private $validator;
public function __construct(ValidatorInterface $validator) {
public function __construct(
ValidatorInterface $validator
) {
$this->validator = $validator;
}

View File

@ -19,7 +19,10 @@ class MetadataCache extends CacheProvider {
/** @var string */
private $directory;
public function __construct($dir, $isReadOnly) {
public function __construct(
$dir,
$isReadOnly
) {
$this->isDevMode = defined('WP_DEBUG') && WP_DEBUG && !$isReadOnly;
$this->directory = rtrim($dir, '/\\');
if (!file_exists($this->directory)) {

View File

@ -15,7 +15,10 @@ class PSRCacheItem implements CacheItemInterface {
/** @var bool */
private $isHit;
public function __construct(string $key, bool $isHit) {
public function __construct(
string $key,
bool $isHit
) {
$this->key = $key;
$this->isHit = $isHit;
}

View File

@ -9,7 +9,10 @@ class PSRMetadataCache implements CacheItemPoolInterface {
/** @var MetadataCache */
private $metadataCache;
public function __construct(string $dir, bool $isReadOnly) {
public function __construct(
string $dir,
bool $isReadOnly
) {
$this->metadataCache = new MetadataCache($dir, $isReadOnly);
}

View File

@ -10,12 +10,11 @@ use MailPoetVendor\Doctrine\Persistence\Mapping\ProxyClassNameResolver as IProxy
* @see https://github.com/doctrine/persistence/blob/2.2.x/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php#L516-L536
*/
class ProxyClassNameResolver implements IProxyClassNameResolver {
/**
* @template T
* @return class-string<T>
*/
public function resolveClassName(string $className) : string {
public function resolveClassName(string $className): string {
$pos = \strrpos($className, '\\' . \MailPoetVendor\Doctrine\Persistence\Proxy::MARKER . '\\');
if ($pos === \false) {
/** @var class-string<T> */

View File

@ -26,7 +26,9 @@ abstract class Repository {
'created_at',
];
public function __construct(EntityManager $entityManager) {
public function __construct(
EntityManager $entityManager
) {
$this->entityManager = $entityManager;
$this->classMetadata = $entityManager->getClassMetadata($this->getEntityClassName());
$this->doctrineRepository = new DoctrineEntityRepository($this->entityManager, $this->classMetadata);

View File

@ -13,7 +13,12 @@ class SerializableConnection extends Connection {
private $config;
private $eventManager;
public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) {
public function __construct(
array $params,
Driver $driver,
Configuration $config = null,
EventManager $eventManager = null
) {
$this->params = $params;
$this->driver = $driver;
$this->config = $config;

View File

@ -3,8 +3,8 @@
namespace MailPoet\Doctrine\Types;
use MailPoetVendor\Carbon\Carbon;
use MailPoetVendor\Doctrine\DBAL\Types\DateTimeTzType;
use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform;
use MailPoetVendor\Doctrine\DBAL\Types\DateTimeTzType;
class DateTimeTzToStringType extends DateTimeTzType {
const NAME = 'datetimetz_to_string';

View File

@ -12,7 +12,10 @@ class ValidationException extends \RuntimeException {
/** @var ConstraintViolationListInterface|ConstraintViolationInterface[] */
private $violations;
public function __construct($resourceName, ConstraintViolationListInterface $violations) {
public function __construct(
$resourceName,
ConstraintViolationListInterface $violations
) {
$this->resourceName = $resourceName;
$this->violations = $violations;

View File

@ -12,7 +12,9 @@ class ValidatorFactory {
/** @var AnnotationReaderProvider */
private $annotationReaderProvider;
public function __construct(AnnotationReaderProvider $annotationReaderProvider) {
public function __construct(
AnnotationReaderProvider $annotationReaderProvider
) {
$this->annotationReaderProvider = $annotationReaderProvider;
}

View File

@ -20,7 +20,11 @@ class AssetsController {
const RECAPTCHA_API_URL = 'https://www.google.com/recaptcha/api.js?render=explicit';
public function __construct(WPFunctions $wp, BasicRenderer $renderer, SettingsController $settings) {
public function __construct(
WPFunctions $wp,
BasicRenderer $renderer,
SettingsController $settings
) {
$this->wp = $wp;
$this->renderer = $renderer;
$this->settings = $settings;

View File

@ -16,7 +16,9 @@ class DoctrinePanel implements IBarPanel {
/** @var DebugStack */
private $sqlLogger;
public function __construct(Configuration $doctrineConfiguration) {
public function __construct(
Configuration $doctrineConfiguration
) {
$this->sqlLogger = new DebugStack();
$doctrineConfiguration->setSQLLogger($this->sqlLogger);
}

View File

@ -14,7 +14,10 @@ class Assets extends AbstractExtension {
/** @var CdnAssetUrl|null */
private $cdnAssetsUrl;
public function __construct(array $globals, CdnAssetUrl $cdnAssetsUrl = null) {
public function __construct(
array $globals,
CdnAssetUrl $cdnAssetsUrl = null
) {
$this->globals = $globals;
$this->cdnAssetsUrl = $cdnAssetsUrl;
}

View File

@ -7,7 +7,7 @@ use MailPoet\Config\Env;
class Template {
public function create($wcEmailSettings) {
$socialIconUrl = Env::$assetsUrl . '/img/newsletter_editor/social-icons';
return [
return [
'content' =>
[
'type' => 'container',