Skip to content
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

Move source classes to the Yoast\WHIPv2 namespace #157

Merged
merged 5 commits into from
Dec 22, 2023
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
46 changes: 13 additions & 33 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@
<!-- Provide the plugin specific prefixes for all naming related sniffs. -->
<property name="prefixes" type="array">
<element value="Yoast\WHIP"/>
<element value="Yoast\WHIPv2"/>
<element value="whip"/>
</property>

<property name="psr4_paths" type="array">
<element key="Yoast\WHIPv2\\" value="src/"/>
<element key="Yoast\WHIP\Tests\\" value="tests/"/>
</property>
</properties>

<!-- Historically, this library has used camelCaps not snakecase for variable and function names. -->
Expand Down Expand Up @@ -74,41 +80,13 @@
</properties>

<!-- Exclude WordPress example function. -->
<exclude-pattern>/src/facades/wordpress\.php$</exclude-pattern>
<exclude-pattern>/src/Facades/wordpress\.php$</exclude-pattern>

<!-- Exclude mocks of WP Core functions which comply with the WP function name rules instead. -->
<exclude-pattern>/tests/Unit/Doubles/WpCoreFunctionsMock\.php$</exclude-pattern>
</rule>


<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->

<rule ref="Yoast.Files.FileName">
<properties>
<property name="psr4_paths" type="array">
<element key="Yoast\WHIP\Tests\\" value="tests/"/>
</property>
</properties>

<include-pattern>/tests/*\.php</include-pattern>
</rule>

<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<property name="src_directory" type="array">
<element value="src"/>
</property>
<property name="psr4_paths" type="array">
<element key="Yoast\WHIP\Tests\\" value="tests/"/>
</property>
</properties>
</rule>


<!--
#############################################################################
SELECTIVE EXCLUSIONS
Expand All @@ -123,7 +101,7 @@

<rule ref="Yoast.NamingConventions.ValidHookName.WrongPrefix">
<!-- Valid usage: Example code for external users of the module. -->
<exclude-pattern>/src/facades/wordpress\.php$</exclude-pattern>
<exclude-pattern>/src/Facades/wordpress\.php$</exclude-pattern>
</rule>

<!-- The variable parameters passed to the WHIP exceptions are mostly used to retrieve
Expand All @@ -133,6 +111,7 @@
</rule>

<rule ref="Yoast.Files.FileName.InvalidFunctionsFileName">
<exclude-pattern>/src/Facades/wordpress\.php$</exclude-pattern>
<exclude-pattern>/tests/Unit/Doubles/WPCoreFunctionsMock\.php$</exclude-pattern>
</rule>

Expand Down Expand Up @@ -161,14 +140,15 @@
<!-- Textdomain is passed in dynamically which will not work correctly with gettext().
Ticket: https://github.com/Yoast/whip/issues/2 -->
<rule ref="WordPress.WP.I18n.NonSingularStringLiteralDomain">
<exclude-pattern>/src/messages/Whip_HostMessage\.php$</exclude-pattern>
<exclude-pattern>/src/messages/Whip_UpgradePhpMessage\.php$</exclude-pattern>
<exclude-pattern>/src/Messages/HostMessage\.php$</exclude-pattern>
<exclude-pattern>/src/Messages/UpgradePhpMessage\.php$</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound">
<!-- These hook setups should be reviewed.
Ticket: https://github.com/Yoast/whip/issues/67 -->
<exclude-pattern>/src/Whip_Host\.php$</exclude-pattern>
<exclude-pattern>/src/Host\.php$</exclude-pattern>
<exclude-pattern>/src/Messages/UpgradePhpMessage\.php$</exclude-pattern>
</rule>

</ruleset>
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"classmap": [
"src/"
],
"psr-4": {
"Yoast\\WHIPv2\\": "src/"
},
"files": [
"src/facades/wordpress.php"
"src/Facades/wordpress.php"
]
},
"autoload-dev": {
Expand All @@ -56,7 +56,7 @@
"Yoast\\WHIP\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=8",
"@putenv YOASTCS_THRESHOLD_ERRORS=10",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WHIP\\Config\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
File renamed without changes.
File renamed without changes.
32 changes: 16 additions & 16 deletions src/Whip_Configuration.php → src/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* WHIP libary file.
*
* @package Yoast\WHIP
*/

namespace Yoast\WHIPv2;

use Yoast\WHIPv2\Exceptions\InvalidType;
use Yoast\WHIPv2\Interfaces\Requirement;

/**
* Class Whip_Configuration.
* Class Configuration.
*/
class Whip_Configuration {
class Configuration {

/**
* The configuration to use.
Expand All @@ -18,15 +18,15 @@ class Whip_Configuration {
private $configuration;

/**
* Whip_Configuration constructor.
* Configuration constructor.
*
* @param array $configuration The configuration to use.
*
* @throws Whip_InvalidType When the $configuration parameter is not of the expected type.
* @throws InvalidType When the $configuration parameter is not of the expected type.
*/
public function __construct( $configuration = array() ) {
if ( ! is_array( $configuration ) ) {
throw new Whip_InvalidType( 'Configuration', $configuration, 'array' );
if ( ! \is_array( $configuration ) ) {
throw new InvalidType( 'Configuration', $configuration, 'array' );
}

$this->configuration = $configuration;
Expand All @@ -35,12 +35,12 @@ public function __construct( $configuration = array() ) {
/**
* Retrieves the configured version of a particular requirement.
*
* @param Whip_Requirement $requirement The requirement to check.
* @param Requirement $requirement The requirement to check.
*
* @return string|int The version of the passed requirement that was detected as a string.
* If the requirement does not exist, this returns int -1.
*/
public function configuredVersion( Whip_Requirement $requirement ) {
public function configuredVersion( Requirement $requirement ) {
if ( ! $this->hasRequirementConfigured( $requirement ) ) {
return -1;
}
Expand All @@ -51,11 +51,11 @@ public function configuredVersion( Whip_Requirement $requirement ) {
/**
* Determines whether the passed requirement is present in the configuration.
*
* @param Whip_Requirement $requirement The requirement to check.
* @param Requirement $requirement The requirement to check.
*
* @return bool Whether or not the requirement is present in the configuration.
*/
public function hasRequirementConfigured( Whip_Requirement $requirement ) {
return array_key_exists( $requirement->component(), $this->configuration );
public function hasRequirementConfigured( Requirement $requirement ) {
return \array_key_exists( $requirement->component(), $this->configuration );
}
}
20 changes: 20 additions & 0 deletions src/Exceptions/EmptyProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Yoast\WHIPv2\Exceptions;

use Exception;

/**
* Class EmptyProperty.
*/
class EmptyProperty extends Exception {

/**
* EmptyProperty constructor.
*
* @param string $property Property name.
*/
public function __construct( $property ) {
parent::__construct( \sprintf( '%s cannot be empty.', (string) $property ) );
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* WHIP libary file.
*
* @package Yoast\WHIP
*/

namespace Yoast\WHIPv2\Exceptions;

use Exception;

/**
* Class InvalidOperatorType.
*/
class Whip_InvalidOperatorType extends Exception {
class InvalidOperatorType extends Exception {

/**
* InvalidOperatorType constructor.
Expand All @@ -18,10 +17,10 @@ class Whip_InvalidOperatorType extends Exception {
*/
public function __construct( $value, $validOperators = array( '=', '==', '===', '<', '>', '<=', '>=' ) ) {
parent::__construct(
sprintf(
\sprintf(
'Invalid operator of %s used. Please use one of the following operators: %s',
$value,
implode( ', ', $validOperators )
\implode( ', ', $validOperators )
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* WHIP libary file.
*
* @package Yoast\WHIP
*/

namespace Yoast\WHIPv2\Exceptions;

use Exception;

/**
* Class InvalidType.
*/
class Whip_InvalidType extends Exception {
class InvalidType extends Exception {

/**
* InvalidType constructor.
Expand All @@ -18,6 +17,6 @@ class Whip_InvalidType extends Exception {
* @param string $expectedType Expected property type.
*/
public function __construct( $property, $value, $expectedType ) {
parent::__construct( sprintf( '%s should be of type %s. Found %s.', $property, $expectedType, gettype( $value ) ) );
parent::__construct( \sprintf( '%s should be of type %s. Found %s.', $property, $expectedType, \gettype( $value ) ) );
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* WHIP libary file.
*
* @package Yoast\WHIP
*/

namespace Yoast\WHIPv2\Exceptions;

use Exception;

/**
* Exception for an invalid version comparison string.
*/
class Whip_InvalidVersionComparisonString extends Exception {
class InvalidVersionComparisonString extends Exception {

/**
* InvalidVersionComparisonString constructor.
Expand All @@ -17,7 +16,7 @@ class Whip_InvalidVersionComparisonString extends Exception {
*/
public function __construct( $value ) {
parent::__construct(
sprintf(
\sprintf(
'Invalid version comparison string. Example of a valid version comparison string: >=5.3. Passed version comparison string: %s',
$value
)
Expand Down
18 changes: 12 additions & 6 deletions src/facades/wordpress.php → src/Facades/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* @package Yoast\WHIP
*/

use Yoast\WHIPv2\MessageDismisser;
use Yoast\WHIPv2\Presenters\WPMessagePresenter;
use Yoast\WHIPv2\RequirementsChecker;
use Yoast\WHIPv2\VersionRequirement;
use Yoast\WHIPv2\WPDismissOption;

if ( ! function_exists( 'whip_wp_check_versions' ) ) {
/**
* Facade to quickly check if version requirements are met.
Expand All @@ -19,11 +25,11 @@ function whip_wp_check_versions( $requirements ) {
return;
}

$config = include __DIR__ . '/../configs/default.php';
$checker = new Whip_RequirementsChecker( $config );
$config = include __DIR__ . '/../Configs/default.php';
$checker = new RequirementsChecker( $config );

foreach ( $requirements as $component => $versionComparison ) {
$checker->addRequirement( Whip_VersionRequirement::fromCompareString( $component, $versionComparison ) );
$checker->addRequirement( VersionRequirement::fromCompareString( $component, $versionComparison ) );
}

$checker->check();
Expand All @@ -35,9 +41,9 @@ function whip_wp_check_versions( $requirements ) {
$dismissThreshold = ( WEEK_IN_SECONDS * 4 );
$dismissMessage = __( 'Remind me again in 4 weeks.', 'default' );

$dismisser = new Whip_MessageDismisser( time(), $dismissThreshold, new Whip_WPDismissOption() );
$dismisser = new MessageDismisser( time(), $dismissThreshold, new WPDismissOption() );

$presenter = new Whip_WPMessagePresenter( $checker->getMostRecentMessage(), $dismisser, $dismissMessage );
$presenter = new WPMessagePresenter( $checker->getMostRecentMessage(), $dismisser, $dismissMessage );

// Prevent duplicate notices across multiple implementing plugins.
if ( ! has_action( 'whip_register_hooks' ) ) {
Expand All @@ -47,7 +53,7 @@ function whip_wp_check_versions( $requirements ) {
/**
* Fires during hooks registration for the message presenter.
*
* @param Whip_WPMessagePresenter $presenter Message presenter instance.
* @param WPMessagePresenter $presenter Message presenter instance.
*/
do_action( 'whip_register_hooks', $presenter );
}
Expand Down
Loading