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 #381

Merged
merged 25 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c600b7
Update libs with wpcs 3 changes [beta] (#373)
dingo-d Oct 26, 2023
70034dd
changing the commands registration order
iruzevic Oct 26, 2023
06da106
addings fixes for php8
iruzevic Oct 26, 2023
619669d
addings fixes for php8
iruzevic Oct 26, 2023
2f9f3d7
addings fixes for php8
iruzevic Oct 26, 2023
3841645
Update composer.json
iruzevic Oct 27, 2023
dcc6c65
updating tests
iruzevic Oct 27, 2023
6580369
updating tests
iruzevic Oct 27, 2023
7d8c23f
updating tests
iruzevic Oct 27, 2023
2fef3b5
updating tests
iruzevic Oct 27, 2023
7776018
updating tests
iruzevic Oct 27, 2023
d84ce12
removing 'Old' function in blocks
iruzevic Oct 27, 2023
be389fe
changing config version and name definition
iruzevic Oct 27, 2023
a61ed51
removing storybook
iruzevic Oct 27, 2023
7bfc16c
fixing missing frontend libs private dir
iruzevic Oct 27, 2023
1d3d368
fixing wrong block dependeny output
iruzevic Oct 27, 2023
8418559
fixing command examples
iruzevic Oct 27, 2023
954b1d9
adding new command for changing version name
iruzevic Oct 29, 2023
401ed35
fixing import command
iruzevic Oct 30, 2023
c5cd932
adding better copy for missing attribute
iruzevic Oct 30, 2023
6c9cf85
adding is used method to every enqueu hook
iruzevic Oct 30, 2023
7089c15
Update src/Misc/VersionCli.php
iruzevic Oct 30, 2023
f74cdb0
adding is used method to every enqueu hook
iruzevic Oct 30, 2023
12ee783
Merge remote-tracking branch 'origin/develop-php8' into develop-php8
iruzevic Oct 30, 2023
5f976a7
adding PR fixes
iruzevic Oct 31, 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
22 changes: 12 additions & 10 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check file permissions"
run: |
Expand All @@ -40,7 +40,7 @@ jobs:
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Find non-printable ASCII characters (box-drawing characters excluded)"
run: |
Expand All @@ -63,10 +63,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
php-version: ["7.4", "8.0", "8.1", "8.2"]
dependencies:
- "lowest"
- "highest"
runs-on: "ubuntu-latest"
steps:
Expand All @@ -77,14 +75,18 @@ jobs:
coverage: "xdebug"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Execute unit tests"
- name: "Execute unit tests without coverage"
run: "composer run test:unit"

- name: "Execute unit tests with coverage"
if: "${{ env.CODECOV_TOKEN && matrix.php-version == '7.4' && matrix.dependencies == 'highest' }}"
run: "composer run test:coverage"

- name: "Upload coverage to Codecov"
Expand Down Expand Up @@ -113,7 +115,7 @@ jobs:
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Validate Composer configuration"
run: "composer validate --strict"
Expand Down Expand Up @@ -142,7 +144,7 @@ jobs:
tools: "cs2pr"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check adherence to EditorConfig"
uses: "greut/eclint-action@v0"
Expand All @@ -166,7 +168,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check exported files"
run: |
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
"source": "https://github.com/infinum/eightshift-libs"
},
"require": {
"php": "^7.4",
"php": "^7.4 || >=8.0",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"php-di/invoker": "^2.3",
"php-di/php-di": "^6.3"
"php-di/invoker": "^2.3.4",
"php-di/php-di": "^7"
},
"require-dev": {
"captainhook/captainhook": "^5.10",
"brain/monkey": "^2.6.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"infinum/eightshift-coding-standards": "^1.6",
"captainhook/captainhook": "^5.10",
"dealerdirect/phpcodesniffer-composer-installer": "^v1.0.0",
"infinum/eightshift-coding-standards": "2.0.0-beta",
"pestphp/pest": "^1.20",
"php-parallel-lint/php-parallel-lint": "^1.3",
"php-stubs/wordpress-stubs": "^5.9",
"php-stubs/wordpress-stubs": "^6.3",
"roave/security-advisories": "dev-master",
"szepeviktor/phpstan-wordpress": "^1.0.3",
"wp-cli/wp-cli": "^2.4",
"szepeviktor/phpstan-wordpress": "^1.3",
"wp-cli/wp-cli": "^2.9",
"yoast/wp-test-utils": "^1.0"
},
"autoload": {
Expand Down
25 changes: 21 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<rule ref="PHPCompatibilityWP"/>

<!-- Support only latest 3 WP versions. -->
<config name="minimum_supported_wp_version" value="5.6"/>
<config name="minimum_supported_wp_version" value="6.0"/>

<exclude-pattern>/src/CompiledContainer\.php</exclude-pattern>

Expand Down Expand Up @@ -55,9 +55,26 @@
<exclude-pattern>*/src/Cli/*</exclude-pattern>
</rule>

<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
<exclude-pattern>*/src/**/*Cli.php</exclude-pattern>
<exclude-pattern>*/src/Cli/*</exclude-pattern>
<!-- Ignore unescaped exceptions. All Eightshift exceptions are escaped. -->
<rule ref="Eightshift.Security.ComponentsEscape.ExceptionNotEscaped">
<severity>0</severity>
</rule>

<!-- Ignore filesystem alternative functions. -->
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_mkdir">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fopen">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fwrite">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fclose">
<severity>0</severity>
</rule>

<rule ref="Generic.Files.LineLength">
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ parameters:
excludePaths:
- src/**/*Example.php
ignoreErrors:
# Uses func_get_args()
- '/^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$/'
# Ignore errors about reflection class variable being undefined. Errors are caught.
- '/^Variable \$reflectionClass might not be defined\.$/'
checkGenericClassInNonGenericObjectType: false
2 changes: 1 addition & 1 deletion src/AdminMenus/AdminReusableBlocksMenuCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getDefaultArgs(): array
'title' => 'Reusable blocks',
'menu_title' => 'Reusable blocks',
'capability' => 'edit_posts',
'menu_icon' => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path d="m18.492 2.33 3.179 3.179a2.25 2.25 0 0 1 0 3.182l-2.423 2.422A2.501 2.501 0 0 1 21 13.5v5a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 18.5v-13A2.5 2.5 0 0 1 5.5 3h5a2.5 2.5 0 0 1 2.387 1.754L15.31 2.33a2.25 2.25 0 0 1 3.182 0ZM11 13H5v5.5a.5.5 0 0 0 .5.5H11v-6Zm7.5 0H13v6h5.5a.5.5 0 0 0 .5-.5v-5a.5.5 0 0 0-.5-.5Zm-4.06-2.001L13 9.559v1.44h1.44Zm-3.94-6h-5a.5.5 0 0 0-.5.5V11h6V5.5a.5.5 0 0 0-.5-.5Z" fill="black"/></svg>', // phpcs:ignore
'menu_icon' => 'dashicons-welcome-widgets-menus',
'menu_position' => 4,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/AdminMenus/AdminReusableBlocksMenuExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$this->getMenuTitle(),
$this->getCapability(),
$this->getMenuSlug(),
'',
'', // @phpstan-ignore-line

Check warning on line 61 in src/AdminMenus/AdminReusableBlocksMenuExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/AdminReusableBlocksMenuExample.php#L61

Added line #L61 was not covered by tests
$this->getIcon(),
$this->getPosition()
);
Expand Down Expand Up @@ -122,7 +122,7 @@
{
// If it's a custom SVG; base64 it.
if (\substr(self::ADMIN_REUSABLE_BLOCKS_MENU_ICON, 0, 4) === '<svg') {
return 'data:image/svg+xml;base64,' . base64_encode(self::ADMIN_REUSABLE_BLOCKS_MENU_ICON); // phpcs:ignore;

Check warning on line 125 in src/AdminMenus/AdminReusableBlocksMenuExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/AdminReusableBlocksMenuExample.php#L125

Added line #L125 was not covered by tests
}

// Otherwise just treat it as a DashIcon.
Expand Down
4 changes: 2 additions & 2 deletions src/AdminMenus/ReusableBlocksHeaderFooterExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
* Admin icon.
*/
public const ADMIN_ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 1A1.5 1.5 0 0 0 0 2.5V4h20V2.5A1.5 1.5 0 0 0 18.5 1h-17ZM20 5H0v10h20V5ZM0 17.5V16h20v1.5a1.5 1.5 0 0 1-1.5 1.5h-17A1.5 1.5 0 0 1 0 17.5ZM19 6H1v8h18V6Z" fill="black"/></svg>'; // phpcs:ignore
public const ADMIN_ICON = 'dashicons-embed-photo';

/**
* Menu position for reusable blocks menu.
Expand Down Expand Up @@ -76,10 +76,10 @@
*
* @return void
*/
public function register(): void

Check warning on line 79 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L79

Added line #L79 was not covered by tests
{
\add_action('admin_init', [$this, 'registerWpSettings']);
\add_action('admin_menu', [$this, 'callback'], $this->getPriorityOrder());

Check warning on line 82 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L81-L82

Added lines #L81 - L82 were not covered by tests
}

/**
Expand All @@ -87,9 +87,9 @@
*
* @return string The text to be displayed in the title tags of the page when the menu is selected.
*/
protected function getTitle(): string

Check warning on line 90 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L90

Added line #L90 was not covered by tests
{
return \esc_html__('%title%', 'eightshift-libs');

Check warning on line 92 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L92

Added line #L92 was not covered by tests
}

/**
Expand All @@ -97,9 +97,9 @@
*
* @return string The text to be used for the menu.
*/
protected function getMenuTitle(): string

Check warning on line 100 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L100

Added line #L100 was not covered by tests
{
return \esc_html__('%menu_title%', 'eightshift-libs');

Check warning on line 102 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L102

Added line #L102 was not covered by tests
}

/**
Expand All @@ -107,9 +107,9 @@
*
* @return string The capability required for reusable block menu to be displayed to the user.
*/
protected function getCapability(): string

Check warning on line 110 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L110

Added line #L110 was not covered by tests
{
return self::ADMIN_MENU_CAPABILITY;

Check warning on line 112 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L112

Added line #L112 was not covered by tests
}

/**
Expand All @@ -119,9 +119,9 @@
* Should be unique for reusable block menu page and only include lowercase alphanumeric,
* dashes, and underscores characters to be compatible with sanitize_key().
*/
protected function getMenuSlug(): string

Check warning on line 122 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L122

Added line #L122 was not covered by tests
{
return self::ADMIN_MENU_SLUG;

Check warning on line 124 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L124

Added line #L124 was not covered by tests
}

/**
Expand All @@ -134,9 +134,9 @@
* e.g. 'dashicons-chart-pie'.
* * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS.
*/
protected function getIcon(): string

Check warning on line 137 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L137

Added line #L137 was not covered by tests
{
return 'data:image/svg+xml;base64,' . base64_encode(self::ADMIN_ICON); // phpcs:ignore;
return self::ADMIN_ICON;

Check warning on line 139 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L139

Added line #L139 was not covered by tests
}

/**
Expand All @@ -155,9 +155,9 @@
* 80 - below Settings
* 100 - below second separator
*/
protected function getPosition(): int

Check warning on line 158 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L158

Added line #L158 was not covered by tests
{
return self::ADMIN_MENU_POSITION;

Check warning on line 160 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L160

Added line #L160 was not covered by tests
}

/**
Expand All @@ -165,9 +165,9 @@
*
* @return string View URI.
*/
protected function getViewComponent(): string

Check warning on line 168 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L168

Added line #L168 was not covered by tests
{
return 'admin-header-footer-picker';

Check warning on line 170 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L170

Added line #L170 was not covered by tests
}

/**
Expand All @@ -182,9 +182,9 @@
*
* @return array<string, mixed> Processed admin menu attributes.
*/
protected function processAttributes($attr): array

Check warning on line 185 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L185

Added line #L185 was not covered by tests
{
return [];

Check warning on line 187 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L187

Added line #L187 was not covered by tests
}

// Supporting functions for defining settings and sections.
Expand All @@ -194,36 +194,36 @@
*
* @return void
*/
public function registerWpSettings(): void

Check warning on line 197 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L197

Added line #L197 was not covered by tests
{
\register_setting(self::ADMIN_MENU_SLUG, self::HEADER_PARTIAL);
\register_setting(self::ADMIN_MENU_SLUG, self::FOOTER_PARTIAL);

Check warning on line 200 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L199-L200

Added lines #L199 - L200 were not covered by tests

\add_settings_section(self::SETTINGS_SECTION_NAME, '', fn () => '', self::ADMIN_MENU_SLUG);

Check warning on line 202 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L202

Added line #L202 was not covered by tests

\add_settings_field(
self::HEADER_PARTIAL,
\__('Header partial', 'eightshift-libs'),
[$this, 'renderPartialSelector'],
self::ADMIN_MENU_SLUG,
self::SETTINGS_SECTION_NAME,
[
'label_for' => self::HEADER_PARTIAL,
'type' => 'header',
]
);

Check warning on line 214 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L204-L214

Added lines #L204 - L214 were not covered by tests

\add_settings_field(
self::FOOTER_PARTIAL,
\__('Footer partial', 'eightshift-libs'),
[$this, 'renderPartialSelector'],
self::ADMIN_MENU_SLUG,
self::SETTINGS_SECTION_NAME,
[
'label_for' => self::FOOTER_PARTIAL,
'type' => 'footer',
]
);

Check warning on line 226 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L216-L226

Added lines #L216 - L226 were not covered by tests
}

/**
Expand All @@ -232,45 +232,45 @@
* @param array<mixed> $args Arguments to pass.
* @return void
*/
public function renderPartialSelector($args): void

Check warning on line 235 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L235

Added line #L235 was not covered by tests
{
$type = isset($args['type']) && $args['type'] === 'header' ? self::HEADER_PARTIAL : self::FOOTER_PARTIAL;

Check warning on line 237 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L237

Added line #L237 was not covered by tests

$reusableBlocksQuery = new WP_Query([
'post_type' => 'wp_block',
'posts_per_page' => 1000, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
'post_status' => 'publish',
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
]);

Check warning on line 245 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L239-L245

Added lines #L239 - L245 were not covered by tests

if ($reusableBlocksQuery->have_posts()) {
$currentValue = \get_option($type);

Check warning on line 248 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L247-L248

Added lines #L247 - L248 were not covered by tests
?>
<select id="<?php echo \esc_attr($args['label_for']); ?>" name="<?php echo \esc_attr($type); ?>">

Check warning on line 250 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L250

Added line #L250 was not covered by tests
<option value="">
&mdash; <?php \esc_html_e('None', 'eightshift-libs'); ?> &mdash;

Check warning on line 252 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L252

Added line #L252 was not covered by tests
</option>

<?php
while ($reusableBlocksQuery->have_posts()) {
$reusableBlocksQuery->the_post();
$postId = (string) \get_the_ID();
$postTitle = \get_the_title();

Check warning on line 259 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L256-L259

Added lines #L256 - L259 were not covered by tests
?>
<option value="<?php echo \esc_attr($postId); ?>"
<?php \selected($currentValue, $postId, true); ?>
>
<?php echo \esc_html($postTitle); ?>
</option>
<?php

Check warning on line 266 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L261-L266

Added lines #L261 - L266 were not covered by tests
}

\wp_reset_postdata();

Check warning on line 269 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L269

Added line #L269 was not covered by tests
?>
</select>
<?php } else { ?>
<i><?php echo \esc_html__('No reusable blocks found.', 'eightshift-libs'); ?></i>

Check warning on line 273 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L271-L273

Added lines #L271 - L273 were not covered by tests
<?php
}
}
Expand All @@ -281,31 +281,31 @@
* @param int|string $partialId Block partial ID.
* @return void
*/
public static function renderPartial($partialId): void

Check warning on line 284 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L284

Added line #L284 was not covered by tests
{
if (empty((string) $partialId)) {
return;

Check warning on line 287 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L286-L287

Added lines #L286 - L287 were not covered by tests
}

$blocksToRender = \parse_blocks(\get_the_content(null, false, $partialId));

Check warning on line 290 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L290

Added line #L290 was not covered by tests

// Filter out empty blocks.
$blocksToRenderFiltered = \array_values(
\array_filter(
$blocksToRender,
static function ($blockArray) {
return !empty($blockArray['blockName']);
}
)
);

Check warning on line 300 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L293-L300

Added lines #L293 - L300 were not covered by tests

$blocksToRenderRendered = \array_map(
static function ($block) {
return \render_block($block);
},
$blocksToRenderFiltered // phpcs:ignore
);

Check warning on line 307 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L302-L307

Added lines #L302 - L307 were not covered by tests

echo Components::ensureString($blocksToRenderRendered); // phpcs:ignore

Check warning on line 309 in src/AdminMenus/ReusableBlocksHeaderFooterExample.php

View check run for this annotation

Codecov / codecov/patch

src/AdminMenus/ReusableBlocksHeaderFooterExample.php#L309

Added line #L309 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion src/AnalyticsGdpr/AnalyticsGdprExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ public function registerGdprModalSettings(): void
/**
* Prepare the data for usage inside of the GDPR modal template.
*
* @return array<string, array> Prepared array filled with the data from options page.
* @return array<string, array<mixed>> Prepared array filled with the data from options page.
*/
public function prepareGdprModalData(): array
{
Expand Down
59 changes: 0 additions & 59 deletions src/Blocks/AbstractBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,39 +153,6 @@ public function getAllBlocksList($allowedBlockTypes, WP_Block_Editor_Context $bl
return $this->getAllAllowedBlocksList([], $blockEditorContext);
}

/**
* Get all blocks with full block name - legacy.
*
* Used to limit what blocks are going to be used in your project using allowed_block_types filter.
*
* @hook allowed_block_types This is a WP 5 - WP 5.7 compatible hook callback. Will not work with WP 5.8!
*
* @param bool|string[] $allowedBlockTypes Array of block type slugs, or boolean to enable/disable all.
* @param WP_Post $post The post resource data.
*
* @return bool|string[] Boolean if you want to disallow or allow all blocks, or a list of allowed blocks.
*/
public function getAllBlocksListOld($allowedBlockTypes, WP_Post $post)
{
if (\gettype($allowedBlockTypes) === 'boolean') {
return $allowedBlockTypes;
}

$allowedBlockTypes = \array_map(
function ($block) {
return $block['blockFullName'];
},
Components::getBlocks()
);

// Allow reusable block.
$allowedBlockTypes[] = 'eightshift-forms/forms';
$allowedBlockTypes[] = 'core/block';
$allowedBlockTypes[] = 'core/template';

return $allowedBlockTypes;
}

/**
* Method used to register all custom blocks with data fetched from blocks manifest.json.
*
Expand Down Expand Up @@ -274,32 +241,6 @@ public function getCustomCategory(array $categories, WP_Block_Editor_Context $bl
);
}

/**
* Create custom category to assign all custom blocks - legacy.
*
* This category will be shown on all blocks list in "Add Block" button.
*
* @hook block_categories This is a WP 5 - WP 5.7 compatible hook callback. Will not work with WP 5.8!
*
* @param array<int, array<string, string|null>> $categories Array of categories for block types.
* @param WP_Post $post Post being loaded.
*
* @return array<int, array<string, string|null>> Array of categories for block types.
*/
public function getCustomCategoryOld(array $categories, WP_Post $post): array
{
return \array_merge(
$categories,
[
[
'slug' => 'eightshift',
'title' => \esc_html__('Eightshift', 'eightshift-libs'),
'icon' => 'admin-settings',
],
]
);
}

/**
* Locate and return template part with passed attributes for wrapper.
*
Expand Down
70 changes: 47 additions & 23 deletions src/Blocks/AbstractBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
self::cliError(
\sprintf(
// translators: %s will be replaced with type of item, and shorten cli path.
"%s files doesn't exist on this path: `%s`. Please check if you have eightshift-frontend-libs installed.",
"%s file doesn't exist on this path: `%s`. Please check if you have eightshift-frontend-libs installed.",

Check warning on line 59 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L59

Added line #L59 was not covered by tests
$type,
$this->getShortenCliPathOutput($source)
)
Expand All @@ -67,32 +67,41 @@
$sourceItems = \array_fill_keys(\array_values($sourceItems), $source);
$sourceItemsPrivate = [];

if ($sourcePrivate) {
if (\is_dir($sourcePrivate)) {
$sourceItemsPrivate = \array_diff(\scandir($sourcePrivate) ?: [], ['..', '.']); // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found
$sourceItemsPrivate = \array_fill_keys(\array_values($sourceItemsPrivate), $sourcePrivate);
}

$sourceItems = \array_merge($sourceItems, $sourceItemsPrivate);

if (($isSingleFolder || $isFile) && isset($sourceItems[$name])) {
$sourceItems = [
$name => $sourceItems[$name],
];
}

if (!$sourceItems) {
self::cliError(
\sprintf(
// translators: %s will be replaced with type of item, and shorten cli path.
"%s files doesn't exist on this path: `%s`. Please check if you have eightshift-frontend-libs installed.",
// translators: %1$s will be replaced with type of item, %2$s the type and %3$s and shorten cli path.
'%1$s %2$s doesn\'t exist on this path: `%3$s`. Please check if you have eightshift-frontend-libs installed.',

Check warning on line 81 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L81

Added line #L81 was not covered by tests
$type,
$isFile ? 'file' : 'folder',

Check warning on line 83 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L83

Added line #L83 was not covered by tests
$this->getShortenCliPathOutput($source)
)
);
}

$itemExists = false;
foreach ($itemsList as $item) {
if (!isset($sourceItems[$item])) {
foreach ($sourceItems as $sourceItem => $sourceFolder) {
if (\strpos($sourceItem, $item) !== false) {
$itemExists = true;
break;
}

// in the case of folders, we should also check the source folders.
if (\strpos($sourceFolder, $item) !== false) {
$itemExists = true;
break;
}
}

if (!$itemExists) {
self::cliError(
\sprintf(
// translators: %s will be replaced with type of item, item name and shorten cli path.
Expand All @@ -104,8 +113,6 @@
);
}

$source = $sourceItems[$item];

$fullSource = Components::joinPaths([$source, $item]);
$fullDestination = Components::joinPaths([$destination, $item]);

Expand Down Expand Up @@ -224,17 +231,34 @@

if ($dependencies) {
$componentsCommandName = UseComponentCli::COMMAND_NAME;
$allDependencies = \array_map(static fn ($item) => Components::camelToKebabCase($item), $dependencies);
$allDependencies = \implode(', ', \array_unique(\array_values($allDependencies)));
$blocksCommandName = UseBlockCli::COMMAND_NAME;

$this->cliLogAlert(\implode("\n", [
"This {$type} may need some dependencies to work correctly.",
'',
'To add them to your project, run:',
"%Uwp boilerplate {$this->getCommandParentName()} {$componentsCommandName} --name='{$allDependencies}'%n",
'',
'If a dependency already exists in your project, you can skip it.',
]), 'info', 'Dependencies found');
$outputComand = [];

if ($componentsDependencies) {
$componentsDependenciesAll = \array_map(static fn ($item) => Components::camelToKebabCase($item), $componentsDependencies);
$componentsDependenciesAll = \implode(', ', \array_unique(\array_values($componentsDependenciesAll)));

$outputComand[] = "%Uwp boilerplate {$this->getCommandParentName()} {$componentsCommandName} --name='{$componentsDependenciesAll}'%n";
}

if ($innerBlocksDependency) {
$innerBlocksDependencyAll = \array_map(static fn ($item) => Components::camelToKebabCase($item), $innerBlocksDependency);

Check warning on line 246 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L245-L246

Added lines #L245 - L246 were not covered by tests
$innerBlocksDependencyAll = \implode(', ', \array_unique(\array_values($innerBlocksDependencyAll)));

$outputComand[] = "%Uwp boilerplate {$this->getCommandParentName()} {$blocksCommandName} --name='{$innerBlocksDependencyAll}'%n";
}

if ($outputComand) {
$this->cliLogAlert(\implode("\n", [
"This {$type} may need some dependencies to work correctly.",
'',
'To add them to your project, run:',
...$outputComand,
'',
'If a dependency already exists in your project, you can skip it.',
]), 'info', 'Dependencies found');
}
}
}

Expand All @@ -254,14 +278,14 @@
$nodeDependencies = $manifest['nodeDependency'] ?? [];

if ($nodeDependencies) {
$this->cliLogAlert(\implode("\n", [
"This {$type} requires some external dependencies to work correctly.",
'',
'To add them to your project, run:',
...\array_map(fn ($package) => "%Unpm install {$package}%n", $nodeDependencies),
'',
'If a dependency already exists in your project, you can skip it.',
]), 'info', 'Packages needed');

Check warning on line 288 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L281-L288

Added lines #L281 - L288 were not covered by tests
}
}
}
Loading
Loading