Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ assets/src
postcss.config.js
tailwind.config.js
phpstan.neon
phpstan-baseline.neon
development.php
playwright.config.ts
test-results
wp-scripts.config.js
README.md
CHANGELOG.md
CHANGELOG.md
14 changes: 11 additions & 3 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ jobs:
name: PHPStan on PHP 8.0
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: simplexml, mysql
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Create the build file
run: |
npm ci
npm run build
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: PHPStan Static Analysis
run: composer phpstan
run: composer phpstan
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
"wp-coding-standards/wpcs": "^3.1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.1.2",
"yoast/phpunit-polyfills": "^4.0",
"phpstan/phpstan": "^1.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"php-stubs/wp-cli-stubs": "^2.8"
"phpstan/phpstan": "^2.1",
"php-stubs/wp-cli-stubs": "^2.8",
"szepeviktor/phpstan-wordpress": "^2.0"
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml --report-summary --report-source",
"phpcs": "phpcs --standard=phpcs.xml --extensions=php -s -d memory_limit=-1",
"phpstan": "phpstan analyse --memory-limit=-1",
"phpstan:generate:baseline": "phpstan analyse --memory-limit=-1 --generate-baseline",
"phpunit": "phpunit --configuration=phpunit.xml",
"install-wp-tests": "bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true"
},
Expand Down
113 changes: 18 additions & 95 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,11 @@ public function inline_bootstrap_script() {
/**
* Add settings links in the plugin listing page.
*
* @param array $links Old plugin links.
* @param string[] $links Old plugin links.
*
* @return array Altered links.
* @return string[] Altered links.
*/
public function add_action_links( $links ) {
if ( ! is_array( $links ) ) {
return $links;
}

return array_merge(
$links,
[
Expand All @@ -599,7 +595,7 @@ public function add_action_links( $links ) {
* @return bool Should show?
*/
public function should_show_notice() {
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
if ( wp_doing_ajax() ) {
return false;
}

Expand Down Expand Up @@ -676,7 +672,7 @@ public function add_notice_upgrade() {
*/
public function should_show_upgrade() {
$current_screen = get_current_screen();
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
if ( wp_doing_ajax() ||
is_network_admin() ||
! current_user_can( 'manage_options' ) ||
! $this->settings->is_connected() ||
Expand Down Expand Up @@ -1003,7 +999,7 @@ public function maybe_redirect() {
return;
}

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( wp_doing_ajax() ) {
return;
}

Expand Down
4 changes: 1 addition & 3 deletions inc/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ public function request( $path, $method = 'GET', $params = [], $extra_headers =
if ( ! empty( $this->api_key ) ) {
$headers['Authorization'] = 'Bearer ' . $this->api_key;
}
if ( is_array( $headers ) ) {
$headers = array_merge( $headers, $extra_headers );
}
$headers = array_merge( $headers, $extra_headers );
$url = trailingslashit( $this->api_root ) . ltrim( $path, '/' );
// If there is a extra, add that as a url var.
if ( 'GET' === $method && ! empty( $params ) ) {
Expand Down
6 changes: 3 additions & 3 deletions inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public static function listen_to_sizes( $value, $orig_w, $orig_h, $dest_w, $dest
/**
* Extract domains and use them as keys for fast processing.
*
* @param array $urls Input urls.
* @param array|null $urls Input urls.
*
* @return array Array of domains as keys.
*/
Expand Down Expand Up @@ -529,7 +529,7 @@ function ( $value ) {
/**
* Check if we can replace the url.
*
* @param string $url Url to change.
* @param string|mixed $url Url to change.
*
* @return bool Either we can replace this url or not.
*/
Expand Down Expand Up @@ -668,7 +668,7 @@ protected function get_optimized_image_url( $url, $width, $height, $resize = []
->width( $width )
->height( $height );

if ( is_array( $resize ) && ! empty( $resize['type'] ) ) {
if ( ! empty( $resize['type'] ) ) {
$optimized_image->resize( $resize['type'], $resize['gravity'] ?? Position::CENTER, $resize['enlarge'] ?? false );

}
Expand Down
2 changes: 1 addition & 1 deletion inc/compatibilities/pinterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function should_load() {
$selectors_array[] = '.heateorSssSharing.heateorSssPinterestBackground';
$load = true;
}
$this->selectors = implode( ', ', array_filter( $selectors_array ) );
$this->selectors = implode( ', ', $selectors_array );
return $load;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/conflicts/conflicting_plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function dismiss_conflicting_plugins() {
* @return bool Should show?
*/
public function should_show_notice() {
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
if ( wp_doing_ajax() ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public function replace_content( $html, $partial = false ) {
$hmac = wp_hash( $profile_id . $time, 'nonce' );
$js_optimizer = str_replace(
[ Profile::PLACEHOLDER, Profile::PLACEHOLDER_MISSING, Profile::PLACEHOLDER_TIME, Profile::PLACEHOLDER_HMAC ],
[ $profile_id, implode( ',', $missing ), $time, $hmac ],
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac ],
$js_optimizer
);
$html = str_replace( Optml_Admin::get_optimizer_script( true ), $js_optimizer, $html );
Expand Down
13 changes: 5 additions & 8 deletions inc/media_offload.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,15 @@ public static function get_image_size_from_width( $sizes, $width, $filename, $ju
/**
* Replace image URLs in the srcset attributes.
*
* @param array $sources Array of image sources.
* @param array $size_array Array of width and height values in pixels (in that order).
* @param string $image_src The 'src' of the image.
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
* @param int $attachment_id Image attachment ID.
* @param array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
* @param array{0: int, 1: int} $size_array Array of width and height values in pixels (in that order).
* @param string $image_src The 'src' of the image.
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
* @param int $attachment_id Image attachment ID or 0.
*
* @return array
*/
public function calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
if ( ! is_array( $sources ) ) {
return $sources;
}

if ( $this->is_legacy_offloaded_attachment( $attachment_id ) ) {
if ( ! Optml_Media_Offload::is_uploaded_image( $image_src ) || ! isset( $image_meta['file'] ) || ! Optml_Media_Offload::is_uploaded_image( $image_meta['file'] ) ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/media_rename/attachment_db_renamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private function replace_in_data( $data, $old_url, $new_url ) {
/**
* Check if a string is serialized
*
* @param string $data String to check.
* @param string|mixed $data String to check.
*
* @return bool True if serialized
*/
Expand Down
3 changes: 1 addition & 2 deletions inc/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ private function fetch_sample_image() {
/**
* Disconnect from optimole service.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param WP_REST_Request $request disconnect rest request.
*/
public function disconnect( WP_REST_Request $request ) {
Expand Down Expand Up @@ -784,7 +783,7 @@ public function check_redirects( WP_REST_Request $request ) {

if ( $processed_images > 0 ) {
$response = wp_remote_get( $value['src'][ rand( 0, $processed_images - 1 ) ], $args );
if ( ! is_wp_error( $response ) && is_array( $response ) ) {
if ( ! is_wp_error( $response ) ) {
$headers = $response['headers']; // array of http header lines
$status_code = $response['response']['code'];
if ( $status_code === 301 ) {
Expand Down
Loading