Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to Human Made coding standards [WIP] (#758)
* Initial migration to Human Made coding standards. * Add autoloader to tests/boostrap.php. * Add autoloader to Travis. * Bundle autoloader. * Fix many tests. * Fix coverage paths. * Update phpcs.ruleset.xml. * Exclude specific files from rule. * Fix false positives for isFormSubmission. * Fixes for HM coding standards. * Point to new inc/ directory * Change isFormSubmission() to better conform to coding standards. * Reduce @codingStandardsIgnore * Trick coding standards, * Last call. * Mr clean. * Mrs Clean. * Add more files to scan. * Fix spacing/formatting to better match HM standards. * Increase code coverage. * Remove @Covers to fix under reporting in PHPStorm, ran phpcbf. * Add editor tests. * Add sanitize test. * Add utility test. * Fix for HM standards. * Fix coding standards error.
- Loading branch information
Ned Zimmerman
committed
May 30, 2017
1 parent
62cba0e
commit 005dccf
Showing
141 changed files
with
5,242 additions
and
5,982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace HM\Autoloader; | ||
|
||
class Autoloader { | ||
const NS_SEPARATOR = '\\'; | ||
|
||
protected $prefix; | ||
protected $prefix_length; | ||
protected $path; | ||
|
||
public function __construct( $prefix, $path ) { | ||
$this->prefix = $prefix; | ||
$this->prefix_length = strlen( $prefix ); | ||
$this->path = trailingslashit( $path ); | ||
} | ||
|
||
public function load( $class ) { | ||
if ( strpos( $class, $this->prefix . self::NS_SEPARATOR ) !== 0 ) { | ||
return; | ||
} | ||
|
||
// Strip prefix from the start (ala PSR-4) | ||
$class = substr( $class, $this->prefix_length + 1 ); | ||
$class = strtolower( $class ); | ||
$file = ''; | ||
|
||
if ( false !== ( $last_ns_pos = strripos( $class, self::NS_SEPARATOR ) ) ) { | ||
$namespace = substr( $class, 0, $last_ns_pos ); | ||
$class = substr( $class, $last_ns_pos + 1 ); | ||
$file = str_replace( self::NS_SEPARATOR, DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR; | ||
} | ||
$file .= 'class-' . str_replace( '_', '-', $class ) . '.php'; | ||
|
||
$path = $this->path . $file; | ||
|
||
if ( file_exists( $path ) ) { | ||
require_once $path; | ||
} | ||
} | ||
} | ||
|
||
function register_class_path( $prefix, $path ) { | ||
$loader = new Autoloader( $prefix, $path ); | ||
spl_autoload_register( [ $loader, 'load' ] ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.