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

Fix function line breaks #446

Merged
merged 27 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb89f86
fix: Fix function line breaks - __(
kryswoj Aug 4, 2023
1ff53f8
fix: Fix function line breaks - trigger_error
kryswoj Aug 4, 2023
4e076e1
Merge branch 'major' into feature/CU-862k7r4f2
kryswoj Aug 7, 2023
aa0bd4e
Merge branch 'major' into feature/CU-862k7r4f2
kryswoj Aug 9, 2023
1bb33d6
refactor: line breaks for __(
kryswoj Aug 9, 2023
6dc90cc
refactor: line breaks for setDescription(
kryswoj Aug 9, 2023
04c5ce3
refactor: line breaks for Register::recipient(
kryswoj Aug 9, 2023
042ffb8
refactor: line breaks for do_action(
kryswoj Aug 9, 2023
059c6d3
refactor: line breaks for add_action(
kryswoj Aug 9, 2023
a5da286
refactor: line breaks for apply_filters(
kryswoj Aug 9, 2023
2459956
refactor: line breaks for sprintf(
kryswoj Aug 9, 2023
2638550
refactor: line breaks for addComponent(
kryswoj Aug 9, 2023
97d1ff9
refactor: line breaks for get_post_meta(
kryswoj Aug 9, 2023
13b0633
refactor: line breaks for method_exists(
kryswoj Aug 9, 2023
9e23f6c
refactor: line breaks for wp_list_pluck(
kryswoj Aug 9, 2023
50f8aae
refactor: line breaks for in_array(
kryswoj Aug 9, 2023
97cc5c5
refactor: line breaks for implode and explode
kryswoj Aug 9, 2023
38fdbda
refactor: line breaks for ifs
kryswoj Aug 14, 2023
58551c5
refactor: line breaks for addGroup and addSection
kryswoj Aug 14, 2023
9f26da8
refactor: sprintf trigger returns for some Comment mergetags
kryswoj Aug 14, 2023
a9845d2
refactor: mostly linebreaks + few sprintfs
kryswoj Aug 14, 2023
8380156
refactor: phpcbf
kryswoj Aug 14, 2023
15a491d
refactor: linebreaks for setFieldData
kryswoj Aug 14, 2023
e562601
refactor: linebreaks for NotificationAdaptFrom + some minors
kryswoj Aug 14, 2023
a352689
refactor: fields concatenation into sprintf
kryswoj Aug 14, 2023
eeab05e
refactor: final clean up
kryswoj Aug 14, 2023
49a9d85
fix: phpstan
kryswoj Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions src/Abstracts/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public function __construct($slug = null, $name = null)
*/
public function __clone()
{

$fields = [];

foreach ($this->formFields as $rawName => $field) {
Expand Down Expand Up @@ -222,18 +221,13 @@ public function hash()
*/
public function addFormField(Interfaces\Fillable $field)
{

if (
in_array(
$field->getRawName(),
$this->restrictedFields,
true
)
) {
if (in_array($field->getRawName(), $this->restrictedFields, true)) {
throw new \Exception(
'You cannot use restricted field name. Restricted names: ' . implode(
', ',
$this->restrictedFields
sprintf(
'%s %s, %s',
'You cannot use restricted field name.',
'Restricted names:',
implode(', ', $this->restrictedFields)
)
);
}
Expand Down Expand Up @@ -304,15 +298,9 @@ public function getRecipientsField()

// Setup the field data if it's available.
if (!empty($this->recipientsResolvedData)) {
$this->setFieldData(
$field,
$this->recipientsResolvedData
);
$this->setFieldData($field, $this->recipientsResolvedData);
} else {
$this->setFieldData(
$field,
$this->recipientsData
);
$this->setFieldData($field, $this->recipientsData);
}

return $field;
Expand Down Expand Up @@ -383,10 +371,7 @@ public function resolveFields(Triggerable $trigger)
continue;
}

$resolved = $this->resolveValue(
$field->getValue(),
$trigger
);
$resolved = $this->resolveValue($field->getValue(), $trigger);
$field->setValue($resolved);
}

Expand Down Expand Up @@ -421,29 +406,17 @@ protected function resolveValue($value, Triggerable $trigger)
$resolved = [];

foreach ($value as $key => $val) {
$key = $this->resolveValue(
$key,
$trigger
);
$val = $this->resolveValue(
$val,
$trigger
);
$key = $this->resolveValue($key, $trigger);
$val = $this->resolveValue($val, $trigger);
$resolved[$key] = $val;
}

return $resolved;
}

$value = apply_filters(
'notification/carrier/field/resolving',
$value
);
$value = apply_filters('notification/carrier/field/resolving', $value);

$resolved = Resolver::resolve(
$value,
$trigger
);
$resolved = Resolver::resolve($value, $trigger);

// Unused tags.
$stripMergeTags = apply_filters(
Expand All @@ -470,17 +443,9 @@ protected function resolveValue($value, Triggerable $trigger)
: do_shortcode($resolved);

// Unescape escaped {.
$resolved = str_replace(
'!{',
'{',
$resolved
);
$resolved = str_replace('!{', '{', $resolved);

return apply_filters(
'notification/carrier/field/value/resolved',
$resolved,
null
);
return apply_filters('notification/carrier/field/value/resolved', $resolved, null);
}

/**
Expand Down Expand Up @@ -555,10 +520,7 @@ public function setData($data)
continue;
}

$this->setFieldData(
$field,
$data[$field->getRawName()]
);
$this->setFieldData($field, $data[$field->getRawName()]);
}

// Set recipients data.
Expand Down
20 changes: 3 additions & 17 deletions src/Abstracts/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,11 @@ abstract class Field implements Interfaces\Fillable
*/
public function __construct($params = [])
{

if (!isset($params['label'], $params['name'])) {
trigger_error(
'Field requires label and name',
E_USER_ERROR
);
trigger_error('Field requires label and name', E_USER_ERROR);
}

$this->fieldTypeHtml = substr(
strrchr(
static::class,
'\\'
),
1
);
$this->fieldTypeHtml = substr(strrchr(static::class, '\\'), 1);

$this->label = $params['label'];
$this->name = $params['name'];
Expand Down Expand Up @@ -204,11 +194,7 @@ public function getValue()
$value = is_string($this->value)
? stripslashes($this->value)
: $this->value;
return apply_filters(
'notification/field/' . $this->getRawName() . '/value',
$value,
$this
);
return apply_filters('notification/field/' . $this->getRawName() . '/value', $value, $this);
}

/**
Expand Down
28 changes: 5 additions & 23 deletions src/Abstracts/MergeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ abstract class MergeTag implements Interfaces\Taggable
*/
public function __construct($params = [])
{

if (!isset($params['slug'], $params['name'], $params['resolver'])) {
trigger_error(
'Merge tag requires resolver',
E_USER_ERROR
);
trigger_error('Merge tag requires resolver', E_USER_ERROR);
}

if (!empty($params['slug'])) {
Expand Down Expand Up @@ -154,32 +150,22 @@ abstract public function sanitize($value);
*/
public function resolve()
{

if ($this->isResolved()) {
return $this->getValue();
}

try {
$value = call_user_func(
$this->resolver,
$this->getTrigger()
);
$value = call_user_func($this->resolver, $this->getTrigger());
} catch (\Throwable $t) {
$value = null;
trigger_error(
esc_html($t->getMessage()),
E_USER_NOTICE
);
trigger_error(esc_html($t->getMessage()), E_USER_NOTICE);
}

if (!empty($value) && !$this->validate($value)) {
$errorType = (defined('WP_DEBUG') && WP_DEBUG)
? E_USER_ERROR
: E_USER_NOTICE;
trigger_error(
'Resolved value is a wrong type',
$errorType
);
trigger_error('Resolved value is a wrong type', $errorType);
}

$this->resolved = true;
Expand Down Expand Up @@ -249,12 +235,8 @@ public function setTrigger(Interfaces\Triggerable $trigger)
*/
public function setResolver($resolver)
{

if (!is_callable($resolver)) {
trigger_error(
'Merge tag resolver has to be callable',
E_USER_ERROR
);
trigger_error('Merge tag resolver has to be callable', E_USER_ERROR);
}

$this->resolver = $resolver;
Expand Down
6 changes: 1 addition & 5 deletions src/Abstracts/Recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ abstract class Recipient implements Interfaces\Receivable
*/
public function __construct($params = [])
{

if (!empty($params['slug'])) {
$this->setSlug($params['slug']);
}
Expand All @@ -49,10 +48,7 @@ public function __construct($params = [])
}

if (!isset($params['default_value'])) {
trigger_error(
'Recipient requires default_value',
E_USER_ERROR
);
trigger_error('Recipient requires default_value', E_USER_ERROR);
}

$this->defaultValue = $params['default_value'];
Expand Down
13 changes: 3 additions & 10 deletions src/Abstracts/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ abstract class Resolver implements Interfaces\Resolvable
*/
public function getSlug()
{
$prepared = str_replace(
'\\',
'-',
static::class
);
$prepared = str_replace(
'BracketSpace-Notification-',
'',
$prepared
);
$prepared = str_replace('\\', '-', static::class);
$prepared = str_replace('BracketSpace-Notification-', '', $prepared);

return sanitize_title_with_dashes($prepared);
}

Expand Down
19 changes: 3 additions & 16 deletions src/Abstracts/Trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function mergeTags()
*/
public function setupMergeTags()
{

if ($this->mergeTagsAdded) {
return;
}
Expand All @@ -107,10 +106,7 @@ public function setupMergeTags()

$this->mergeTagsAdded = true;

do_action(
'notification/trigger/merge_tags',
$this
);
do_action('notification/trigger/merge_tags', $this);
}

/**
Expand Down Expand Up @@ -141,10 +137,7 @@ public function clearMergeTags()
public function addAction($tag, $priority = 10, $acceptedArgs = 1)
{
if (empty($tag)) {
trigger_error(
'Action tag cannot be empty',
E_USER_ERROR
);
trigger_error('Action tag cannot be empty', E_USER_ERROR);
}

array_push(
Expand All @@ -167,12 +160,8 @@ public function addAction($tag, $priority = 10, $acceptedArgs = 1)
*/
public function removeAction($tag, $priority = 10, $deprecated = null)
{

if (empty($tag)) {
trigger_error(
'Action tag cannot be empty',
E_USER_ERROR
);
trigger_error('Action tag cannot be empty', E_USER_ERROR);
}

foreach ($this->actions as $actionIndex => $action) {
Expand Down Expand Up @@ -244,7 +233,6 @@ public function addQuickMergeTag($propertyName, $label, $group = null)
*/
public function removeMergeTag($mergeTagSlug)
{

foreach ($this->mergeTags as $index => $mergeTag) {
if ($mergeTag->getSlug() === $mergeTagSlug) {
unset($this->mergeTags[$index]);
Expand All @@ -266,7 +254,6 @@ public function removeMergeTag($mergeTagSlug)
*/
public function getMergeTags($type = 'all', $grouped = false)
{

if (!$this->mergeTagsAdded) {
$this->setupMergeTags();
}
Expand Down
12 changes: 4 additions & 8 deletions src/Admin/CheckRestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ public function testRestApi()
)
);

$message = json_decode(
wp_remote_retrieve_body($response),
true
);
$message = json_decode(wp_remote_retrieve_body($response), true);

$isAvailable = false;

if (
is_array($message) && array_key_exists(
'data',
$message
) && $message['data'] === 'RestApi'
is_array($message) &&
array_key_exists('data', $message) &&
$message['data'] === 'RestApi'
) {
return;
}
Expand Down
Loading
Loading