| 1 |
<?php |
| 2 |
/** |
| 3 |
* DocHooks Checker class |
| 4 |
* |
| 5 |
* @package micropackage/requirements |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Micropackage\Requirements\Checker; |
| 9 |
|
| 10 |
use Micropackage\Requirements\Abstracts; |
| 11 |
use Micropackage\Requirements\Requirements; |
| 12 |
|
| 13 |
/** |
| 14 |
* DocHooks Checker class |
| 15 |
*/ |
| 16 |
class DocHooks extends Abstracts\Checker { |
| 17 |
|
| 18 |
/** |
| 19 |
* Checker name |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $name = 'dochooks'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Checks if the requirement is met |
| 27 |
* |
| 28 |
* @dochooks-test |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @throws \Exception When provided value is not a string or numeric. |
| 32 |
* @param mixed $enabled If dochooks should be enabled or disabled. |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function check( $enabled ) { |
| 36 |
|
| 37 |
if ( ! is_bool( $enabled ) ) { |
| 38 |
throw new \Exception( 'DocHooks Check requires bool parameter' ); |
| 39 |
} |
| 40 |
|
| 41 |
$reflector = new \ReflectionClass( $this ); |
| 42 |
$has_comment = false !== strpos( $reflector->getMethod( 'check' )->getDocComment(), '@dochooks-test' ); |
| 43 |
|
| 44 |
if ( ! $has_comment && $enabled ) { |
| 45 |
$this->add_error( __( 'Support for DocHooks is required. You need to disable OPCache comment stripping.', Requirements::$textdomain ) ); |
| 46 |
} |
| 47 |
|
| 48 |
if ( $has_comment && ! $enabled ) { |
| 49 |
$this->add_error( __( 'Support for DocHooks is superfluous', Requirements::$textdomain ) ); |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
|