-
Notifications
You must be signed in to change notification settings - Fork 6
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
Separate declarations from side-effects #7
Comments
<?php
/**
* Autoloader for WordPress.
*
* @package Underpin
* @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions
* @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example
*/
declare( strict_types = 1 );
namespace Underpin;
use function spl_autoload_register;
spl_autoload_register(
/**
* Closure of the autoloader.
*
* @param class-string $class_name The fully-qualified class name.
* @return void
*/
static function ( $class_name ) {
$project_namespace = __NAMESPACE__ . '\\';
$length = strlen( $project_namespace );
// Class is not in our namespace.
if ( 0 !== strncmp( $project_namespace, $class_name, $length ) ) {
return;
}
// E.g. Model\Item
$relative_class_name = substr( $class_name, $length );
// E.g. model/Item.php
$name_parts = explode( '\\', $relative_class_name );
$last_part = array_pop( $name_parts );
$file = sprintf(
'%1$s/lib%2$s/%3$s.php',
__DIR__,
array() === $name_parts ? '' : '/' . strtolower( str_replace( '_', '-', implode( '/', $name_parts ) ) ),
$last_part
);
if ( ! is_file( $file ) ) {
return;
}
require $file;
}
); |
We currently have a mix of PSR-4 class file names and WPCS directory names.
|
Going further: |
After everything is clean and tidy: includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
# level: max
level: 5
inferPrivatePropertyTypeFromConstructor: true
paths:
- lib/
ignoreErrors:
# Uses func_get_args()
- '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
Will keep you entertained for 2 hours. |
Nope. This plugin is unapologetic-ally intended to avoid that. To me, if you want to use WPCS, use WordPress. I appreciate the information in this, would it be possible to have a PR submitted? That would make it way easier to understand the differences, and test. |
Done. |
The text was updated successfully, but these errors were encountered: