Skip to content
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
49 changes: 49 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PHP CodeSniffer

on:
push:
branches: [ trunk ]
pull_request:

jobs:
phpcs:
runs-on: ubuntu-latest
name: PHP CodeSniffer

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, json
coverage: none
tools: composer:v2
ini-values: memory_limit=1G

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-dev --optimize-autoloader

- name: Install dev dependencies for PHPCS
run: composer install --dev --prefer-dist --no-progress --no-suggest --optimize-autoloader

- name: Run PHP CodeSniffer
run: php vendor/bin/phpcs -d memory_limit=1G . -n

- name: Annotate PHPCS results
if: failure()
run: |
echo "::error::PHP CodeSniffer found coding standard violations. Please run 'composer run-script lint-fix' to auto-fix issues where possible, or manually fix the remaining issues."
49 changes: 24 additions & 25 deletions bin/build-phar/DataLiberationBoxCompactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@

use KevinGH\Box\Compactor\Compactor;

class DataLiberationBoxCompactor implements Compactor
{
/**
* {@inheritdoc}
*/
public function compact(string $file, string $contents): string
{
if (!preg_match('/\.(php|json|lock)$/', $file)) {
return '';
}
class DataLiberationBoxCompactor implements Compactor {

if (
str_contains($file, 'platform_check.php') ||
str_contains($file, '/tests/') ||
str_contains($file, '/.git/') ||
str_contains($file, '/.github/') ||
str_contains($file, '/bin/')
) {
return '';
}
/**
* {@inheritdoc}
*/
public function compact( string $file, string $contents ): string {
if ( ! preg_match( '/\.(php|json|lock)$/', $file ) ) {
return '';
}

if( str_contains($contents, 'Your Composer dependencies require ') ) {
return '';
}
if (
str_contains( $file, 'platform_check.php' ) ||
str_contains( $file, '/tests/' ) ||
str_contains( $file, '/.git/' ) ||
str_contains( $file, '/.github/' ) ||
str_contains( $file, '/bin/' )
) {
return '';
}

return $contents;
}
}
if ( str_contains( $contents, 'Your Composer dependencies require ' ) ) {
return '';
}

return $contents;
}
}
2 changes: 1 addition & 1 deletion bin/build-phar/box.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$box_base_path = dirname(getenv('BOX_BASE_PATH'));
$box_base_path = dirname( getenv( 'BOX_BASE_PATH' ) );
require_once $box_base_path . '/../autoload.php';
require_once __DIR__ . '/DataLiberationBoxCompactor.php';
require_once $box_base_path . '/box';
18 changes: 10 additions & 8 deletions bin/build-phar/smoke-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
* any data. We're just making sure the importer can
* be created without throwing an exception.
*/
$c = WordPress\DataLiberation\Importer\StreamImporter::create_for_wxr_file(__DIR__ . '/nosuchfile.xml', [
'uploads_path' => __DIR__ . '/uploads',
'new_site_url' => 'https://smoke-test.org',
'new_site_content_root_url' => 'https://smoke-test.org',
'new_media_root_url' => 'https://smoke-test.org',
]);
$c = WordPress\DataLiberation\Importer\StreamImporter::create_for_wxr_file(
__DIR__ . '/nosuchfile.xml',
array(
'uploads_path' => __DIR__ . '/uploads',
'new_site_url' => 'https://smoke-test.org',
'new_site_content_root_url' => 'https://smoke-test.org',
'new_media_root_url' => 'https://smoke-test.org',
)
);

WordPress\DataLiberation\URL\WPURL::parse('https://example.com');
WordPress\DataLiberation\URL\WPURL::parse( 'https://example.com' );

echo 'Stream importer created!';

7 changes: 2 additions & 5 deletions bin/build-phar/truncate-composer-checks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Box, very annoyingly, force-adds a platform_check.php file
* into the final built .phar archive. The vendor libraries
Expand All @@ -8,10 +7,8 @@
*/

$file = $argv[1];
$phar = new Phar($file);
$phar = new Phar( $file );
$phar->startBuffering();
$phar['.box/bin/check-requirements.php'] = '';
$phar['.box/bin/check-requirements.php'] = '';
$phar['vendor/composer/platform_check.php'] = ''; // Set to empty string to truncate
$phar->stopBuffering();


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class BaseByteReadStream implements ByteReadStream {
* fox jumps over the lazy dog.
* ^--^
* consumed but retained for seek()-ing backwards.
*
*
* @var int
*/
protected $max_lookbehind_bytes = 2048;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"build-blueprints-phar": "box compile -c phar-blueprints.json",
"regenerate-json-schema": "node components/Blueprints/Versions/Version2/json-schema/regenerate-schema.ts",
"test": "phpunit -c phpunit.xml",
"lint": "phpcs .",
"lint-fix": "phpcbf ."
"lint": "phpcs -d memory_limit=1G .",
"lint-fix": "phpcbf -d memory_limit=1G ."
},
"repositories": [
{
Expand Down
22 changes: 0 additions & 22 deletions file.php

This file was deleted.

4 changes: 4 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>*/vendor-patched/*</exclude-pattern>
<exclude-pattern>*/Tests/*</exclude-pattern>
<exclude-pattern>plugins/*</exclude-pattern>
<exclude-pattern>examples/*</exclude-pattern>
<exclude-pattern>rector.php</exclude-pattern>
<exclude-pattern>components/CORSProxy/cors-proxy-functions.php</exclude-pattern>
<rule ref="PHPCompatibility">
</rule>
<rule ref="components/ToolkitCodingStandards/WordPressToolkitCodingStandards/ruleset.xml"/>
Expand Down
Loading
Loading