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

WIP : PHP8 #761

Merged
merged 8 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/components/image/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
continue;
}

$breakpointValue = $globalManifest['globalVariables']['breakpoints'][$breakpoint] ?? ''; // @phpstan-ignore-line
$breakpointValue = $globalManifest['globalVariables']['breakpoints'][$breakpoint] ?? '';

if (!$breakpointValue) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/components/lists/lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$listsContent = Components::checkAttr('listsContent', $attributes, $manifest);
$listsType = Components::checkAttr('listsOrdered', $attributes, $manifest);

$listsTypeOptions = array_map(static fn($option) => $option['value'], $manifest['options']['listsOrdered'] ?? []); // @phpstan-ignore-line
$listsTypeOptions = array_map(static fn($option) => $option['value'], $manifest['options']['listsOrdered'] ?? []);

if (!in_array($listsType, $listsTypeOptions, true)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
continue;
}

if (!$socialNetworksShareMode && !isset($manifest['networks'][$network['id']]['url'])) { // @phpstan-ignore-line
if (!$socialNetworksShareMode && !isset($manifest['networks'][$network['id']]['url'])) {
continue;
}

if ($socialNetworksShareMode && !isset($manifest['networks'][$network['id']]['shareUrl'])) { // @phpstan-ignore-line
if ($socialNetworksShareMode && !isset($manifest['networks'][$network['id']]['shareUrl'])) {
continue;
}

Expand Down Expand Up @@ -64,21 +64,21 @@
<?php
if ($socialNetworksShareMode) {
foreach ($networksToShow as $networkName) {
$shareUrl = $manifest['networks'][$networkName]['shareUrl'] ?? ''; // @phpstan-ignore-line
$shareUrl = str_replace('POST_TITLE', get_the_title(), $shareUrl); // @phpstan-ignore-line
$shareUrl = str_replace('POST_URL', get_the_permalink(), $shareUrl); // @phpstan-ignore-line
$shareUrl = str_replace('POST_FEATURED_IMAGE', get_the_post_thumbnail_url(get_the_ID(), 'large'), $shareUrl); // @phpstan-ignore-line
$shareUrl = $manifest['networks'][$networkName]['shareUrl'] ?? '';
$shareUrl = str_replace('POST_TITLE', get_the_title(), $shareUrl);
$shareUrl = str_replace('POST_URL', get_the_permalink(), $shareUrl);
$shareUrl = str_replace('POST_FEATURED_IMAGE', get_the_post_thumbnail_url(get_the_ID(), 'large'), $shareUrl);
?>
<button
class="<?php echo esc_html($itemClass); ?>"
data-network="<?php echo esc_attr($networkName); ?>"
data-share-url="<?php echo esc_url($shareUrl); ?>" <?php // @phpstan-ignore-line ?>
data-share-url="<?php echo esc_url($shareUrl); ?>" <?php ?>
data-page-title="<?php echo esc_attr(get_the_title()); ?>"
data-page-url="<?php echo esc_url(get_the_permalink()); ?>" <?php // @phpstan-ignore-line ?>
data-page-url="<?php echo esc_url(get_the_permalink()); ?>" <?php ?>
>
<?php
// phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped
echo $manifest['networks'][$networkName]['icon'] ?? ''; // @phpstan-ignore-line
echo $manifest['networks'][$networkName]['icon'] ?? '';
?>
</button>
<?php }
Expand All @@ -87,14 +87,14 @@ class="<?php echo esc_html($itemClass); ?>"
?>
<a
class="<?php echo esc_html($itemClass); ?>"
href="<?php echo esc_url($manifest['networks'][$networkName]['url'] ?? ''); ?>" <?php // @phpstan-ignore-line ?>
title="<?php echo esc_attr($manifest['networks'][$networkName]['title'] ?? ''); ?>" <?php // @phpstan-ignore-line ?>
href="<?php echo esc_url($manifest['networks'][$networkName]['url'] ?? ''); ?>" <?php ?>
title="<?php echo esc_attr($manifest['networks'][$networkName]['title'] ?? ''); ?>" <?php ?>
target="_blank"
rel="noreferrer noopener"
>
<?php
// phpcs:ignore Eightshift.Security.ComponentsEscape.OutputNotEscaped
echo $manifest['networks'][$networkName]['icon'] ?? ''; // @phpstan-ignore-line
echo $manifest['networks'][$networkName]['icon'] ?? '';
?>
</a>
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class="<?php echo esc_attr($blockClass); ?>"
function ($item) {
return $item['value'];
},
$featuredCategoriesManualTerms // @phpstan-ignore-line
$featuredCategoriesManualTerms
),
];

$allTerms = get_terms($args); // @phpstan-ignore-line
$allTerms = get_terms($args);

if (!is_iterable($allTerms)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ function ($item) {
(array)$featuredContentTerms
);
} elseif ($featuredContentUseCurrentTerm && $post instanceof WP_Post) {
$currentTerms = get_the_terms($post->ID, strval($featuredContentTaxonomy)); // @phpstan-ignore-line
$currentTerms = get_the_terms($post->ID, strval($featuredContentTaxonomy));

if ($currentTerms) {
$args['tax_query'][0]['terms'] = [$currentTerms[0]->term_id]; // @phpstan-ignore-line
$args['tax_query'][0]['terms'] = [$currentTerms[0]->term_id];
}
} else {
$args['tax_query'][0]['operator'] = 'NOT IN'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
Expand Down
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/custom/map/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$mapControls = Components::checkAttr('mapControls', $attributes, $manifest);

// Take only active map layers and clean them up a bit so the output JSON is smaller.
$activeLayers = array_filter($mapLayers, fn ($layer) => $layer['hidden'] === false); // @phpstan-ignore-line
$activeLayers = array_filter($mapLayers, fn ($layer) => $layer['hidden'] === false);

$activeLayers = array_map(function ($layer) {
unset($layer['id']);
Expand Down
2 changes: 1 addition & 1 deletion blocks/init/src/Blocks/custom/site-footer/site-footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$siteFooterLinks = Components::checkAttr('siteFooterLinks', $attributes, $manifest);

if (!empty($siteFooterLinks)) {
$siteFooterLinks = array_filter($siteFooterLinks, fn($item) => !empty($item['text']) && !empty($item['url'])); // @phpstan-ignore-line
$siteFooterLinks = array_filter($siteFooterLinks, fn($item) => !empty($item['text']) && !empty($item['url']));
}

$linksClass = Components::selector($blockClass, $blockClass, 'links');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$siteNavigationLinks = Components::checkAttr('siteNavigationLinks', $attributes, $manifest) ?? [];

if (!empty($siteNavigationLinks)) {
$siteNavigationLinks = array_filter($siteNavigationLinks, fn($item) => !empty($item['text']) && !empty($item['url'])); // @phpstan-ignore-line
$siteNavigationLinks = array_filter($siteNavigationLinks, fn($item) => !empty($item['text']) && !empty($item['url']));
}

$navbarClass = Components::classnames([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

$tableOfContentsHeadingLevels = Components::checkAttr('tableOfContentsHeadingLevels', $attributes, $manifest);

$headingLevelsToUse = implode(',', array_keys(array_filter($tableOfContentsHeadingLevels, fn($v) => $v))); // @phpstan-ignore-line
$headingLevelsToUse = implode(',', array_keys(array_filter($tableOfContentsHeadingLevels, fn($v) => $v)));
?>

<div class="<?php echo esc_attr($tocClass); ?>" data-levels="<?php echo esc_attr($headingLevelsToUse); ?>">
Expand Down
3 changes: 0 additions & 3 deletions blocks/init/storybook/babel.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions blocks/init/storybook/main.js

This file was deleted.

5 changes: 0 additions & 5 deletions blocks/init/storybook/preview-body.html

This file was deleted.

3 changes: 0 additions & 3 deletions blocks/init/storybook/preview-head.html

This file was deleted.

31 changes: 0 additions & 31 deletions blocks/init/storybook/preview.js

This file was deleted.

7 changes: 0 additions & 7 deletions blocks/init/storybook/webpack.config.js

This file was deleted.

19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"source": "https://github.com/infinum/eightshift-frontend-libs"
},
"require": {
"php": "^7.4 || <8.0",
"php": ">=7.4",
"ext-json": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"infinum/eightshift-coding-standards": "^1.6",
"dealerdirect/phpcodesniffer-composer-installer": "^v1.0.0",
"infinum/eightshift-coding-standards": "2.0.0-beta",
"infinum/eightshift-libs-stubs": "^0.7.0",
"php-stubs/wordpress-stubs": "^6.0",
"szepeviktor/phpstan-wordpress": "^1.0.3"
"php-stubs/wordpress-stubs": "^6.3",
"szepeviktor/phpstan-wordpress": "^1.1.7"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -45,8 +45,11 @@
}
},
"scripts": {
"analyze": "@php ./vendor/bin/phpstan analyze",
"standards:check": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"standards:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
"test:types": "@php ./vendor/bin/phpstan analyze",
"test:standards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 7.4-",
"test": [
"@test:standards",
"@test:types"
]
}
}
10 changes: 8 additions & 2 deletions scripts/editor/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ export const checkAttr = (key, attributes, manifest, undefinedAllowed = false) =
// Check current component attributes.
const manifestKey = manifest.attributes[key];

let tipOutput = '';

if ('components' in manifest) {
tipOutput = ' If you are using additional components, check if you used the correct block/component prefix in your attribute name.';
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
}

// Bailout if key is missing.
if (typeof manifestKey === 'undefined') {
if ('blockName' in manifest) {
throw Error(`${key} key does not exist in the ${manifest.blockName} block manifest. Please check your implementation.`);
throw Error(`${key} key does not exist in the ${manifest.blockName} block manifest. Please check your implementation.${tipOutput}`);
} else {
throw Error(`${key} key does not exist in the ${manifest.componentName} component manifest. Please check your implementation.`);
throw Error(`${key} key does not exist in the ${manifest.componentName} component manifest. Please check your implementation.${tipOutput}`);
}
}

Expand Down
4 changes: 4 additions & 0 deletions setup/create-wp-project/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ After the script is finished, please follow the instructions provided by the set

All additional steps after the initial setup are done using WP_CLI commands, so please make sure that you have WP-CLI set and ready to use.

To make sure you use the latest version of npx command you can add `@latest` flag to the command:

`npx create-wp-project@latest`

## Specify version to create

If you want to specify a version of Eightshift Libs or Frontend Libs to use, you can use add two additional attributes to this command to specify a branch or release to use:
Expand Down
2 changes: 1 addition & 1 deletion setup/create-wp-project/src/basics/argument-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const requirementCheck = async () => {
`${chalk.gray(' Check with')} ${chalk.gray.underline('node -v')}`,
'- Composer (LTS recommended)',
`${chalk.gray(' Check with')} ${chalk.gray.underline('composer -V')}`,
'- WP CLI', `${chalk.gray(' Check with')} ${chalk.gray.underline('wp --info')}`,
'- WP CLI (2.9.0+)', `${chalk.gray(' Check with')} ${chalk.gray.underline('wp --info')}`,
'- Git',
`${chalk.gray(' Check with')} ${chalk.gray.underline('git --version')}`
].join("\n"), 'Requirements');
Expand Down
Loading