mirror of
https://github.com/discourse/wp-discourse.git
synced 2025-08-17 18:11:19 +08:00
* Add base log classes * Return maxFiles to normal level * Use protected class variables for folder names in folder-manager * Add unit tests for logger classes && various logger improvements * Add log viewer * Fix initialization sequence in LogViewer * Add wp-discourse settings to plugin meta * Remove metafile comments * Add partial coverage and annotate LogViewer * Add code coverage reporting and a tests readme * Tests readme xdebug section formatting * Add logging and tests to discourse-publish This abstracts remote post components to make it possible to add consistent error and log handling. Also adds basic tests coverage for discourse-publish. * Add successful publication test * Add working tests for publish_after_create and publish_after_update * Always remove test files and database upon install * Cleanup copy and assertions for existing tests * Final cleanup && verbose setting * Improve structure of publish test * Final tests, linting, security and cleanup * PHP 7.0 Compatibility * PHP 5.6 Compatibility * JSHint fixes * Update file-handler.php * Update log viewer title * Use older monolog and update file_handler function signatures * Add nonce to other view_log action * Namespace production composer packages and define build process * Update COMPOSER.md * Update FORMATTING.md * Log viewer style, naming and log-refresh improvements * Filter out all return type declarations during scoping * JsHint: Don't use default params * Update COMPOSER.md * Copy fix * Update scoper patchers notes * Address syntax issues - Remove >php7 syntax from non-required files - Add phpcs pattern exclusions to phpcs.xml - update formatting docs * discourse-publish: address all phpcs notices and add more tests Note: also added dealerdirect/phpcodesniffer-composer-installer to handle local requiring of codesniffer * Handle all phpcs warnings in lib/logs * Add todo: review phpcs exclusions to discourse-publish * Monolog cleanup - Remove unused monolog handlers, processors and formatters - Add vendor_namespaced to excluded phpcs patterns * Update CI versions to those used in composer * Switch to using composer directly in CI actions * Composer is packaged in shivammathur/setup-php * Setup PHPCS via shivammathur/setup-php * Incorrect tools key * Use vendor/bin version of phpcs * Install composer dependencies via ramsey/composer-install * Update composer.lock to composer 2 and --ignore-platform-reqs * Install lowest version of dependencies * Move dependency-versions key * Move composer-options key * Exclude vendor directory from syntax checker * Add vendor to jshintignore * Update phpcs.xml to properly exclude js css and config files * Address phpcs issues in log-viewer * Fix remaining whitespace issues created in this PR * Remove out of date sniffs and exclude specific code where necessary * Final cleanup * Properly escape html in log viewer * Remove unnecessary verbiage from documentation * Bump plugin's version to 2.2.4 Co-authored-by: Angus McLeod <angus@mcleod.org.au>
132 lines
5.5 KiB
PHP
132 lines
5.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Isolated\Symfony\Component\Finder\Finder;
|
|
|
|
return [
|
|
// The prefix configuration. If a non null value will be used, a random prefix will be generated.
|
|
'prefix' => 'WPDiscourse',
|
|
|
|
// By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
|
|
// directory. You can however define which files should be scoped by defining a collection of Finders in the
|
|
// following configuration key.
|
|
//
|
|
// For more see: https://github.com/humbug/php-scoper#finders-and-paths
|
|
'finders' => [
|
|
Finder::create()
|
|
->files()
|
|
->ignoreVCS(true)
|
|
->in('vendor')
|
|
->path([
|
|
'Monolog/Formatter/FormatterInterface.php',
|
|
'Monolog/Formatter/NormalizerFormatter.php',
|
|
'Monolog/Formatter/LineFormatter.php',
|
|
'Monolog/Handler/AbstractHandler.php',
|
|
'Monolog/Handler/AbstractProcessingHandler.php',
|
|
'Monolog/Handler/HandlerInterface.php',
|
|
'Monolog/Handler/NullHandler.php',
|
|
'Monolog/Handler/StreamHandler.php',
|
|
'Monolog/ResettableInterface.php',
|
|
'Monolog/Logger.php',
|
|
'Monolog/Utils.php',
|
|
'monolog/LICENSE'
|
|
]),
|
|
Finder::create()
|
|
->files()
|
|
->ignoreVCS(true)
|
|
->notName('/.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
|
|
->exclude([
|
|
'doc',
|
|
'test',
|
|
'test_old',
|
|
'Test',
|
|
'tests',
|
|
'Tests',
|
|
'vendor-bin',
|
|
])
|
|
->in('vendor')
|
|
->path('/^psr/')
|
|
],
|
|
|
|
// Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving
|
|
// a file untouched.
|
|
// Paths are relative to the configuration file unless if they are already absolute
|
|
'files-whitelist' => [],
|
|
|
|
// When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
|
|
// original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
|
|
// support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
|
|
// heart contents.
|
|
//
|
|
// For more see: https://github.com/humbug/php-scoper#patchers
|
|
'patchers' => [
|
|
function (string $filePath, string $prefix, string $contents) {
|
|
$lines = explode( "\n", $contents );
|
|
|
|
foreach ( $lines as $index => $line ) {
|
|
|
|
// Ensure functions do not have return type declarations, which are not supported in PHP 5.*.
|
|
// See further https://github.com/Seldaek/monolog/issues/1537.
|
|
if ( preg_match( '/\h(function)\h/', $line ) && ltrim($line)[0] !== '*' ) {
|
|
$last_bracket_index = strripos( $line, ')' );
|
|
|
|
if ( $last_bracket_index ) {
|
|
$new_line = substr( $line, 0, $last_bracket_index );
|
|
$new_line .= ")";
|
|
|
|
$line_without_args = preg_replace( '/\(([^()]*+|(?R))*\)/', '', $line );
|
|
|
|
if ( strpos( $line_without_args, "{" ) !== false ) {
|
|
$new_line .= " {";
|
|
}
|
|
|
|
if ( substr( $line, -1 ) == ";" ) {
|
|
$new_line .= ";";
|
|
}
|
|
|
|
$lines[ $index ] = $new_line;
|
|
}
|
|
}
|
|
|
|
// Remove strict_type declarations
|
|
if ( preg_match( '/strict_types/', $line ) && ltrim($line)[0] !== '*' ) {
|
|
unset( $lines[ $index ] );
|
|
}
|
|
|
|
}
|
|
|
|
return implode( "\n", $lines );
|
|
},
|
|
],
|
|
|
|
// PHP-Scoper's goal is to make sure that all code for a project lies in a distinct PHP namespace. However, you
|
|
// may want to share a common API between the bundled code of your PHAR and the consumer code. For example if
|
|
// you have a PHPUnit PHAR with isolated code, you still want the PHAR to be able to understand the
|
|
// PHPUnit\Framework\TestCase class.
|
|
//
|
|
// A way to achieve this is by specifying a list of classes to not prefix with the following configuration key. Note
|
|
// that this does not work with functions or constants neither with classes belonging to the global namespace.
|
|
//
|
|
// Fore more see https://github.com/humbug/php-scoper#whitelist
|
|
'whitelist' => [
|
|
// 'PHPUnit\Framework\TestCase', // A specific class
|
|
// 'PHPUnit\Framework\*', // The whole namespace
|
|
// '*', // Everything
|
|
],
|
|
|
|
// If `true` then the user defined constants belonging to the global namespace will not be prefixed.
|
|
//
|
|
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
|
|
'whitelist-global-constants' => true,
|
|
|
|
// If `true` then the user defined classes belonging to the global namespace will not be prefixed.
|
|
//
|
|
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
|
|
'whitelist-global-classes' => true,
|
|
|
|
// If `true` then the user defined functions belonging to the global namespace will not be prefixed.
|
|
//
|
|
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
|
|
'whitelist-global-functions' => true,
|
|
];
|