Skip to content

Commit

Permalink
Changing default namespace to match organization standard (#379)
Browse files Browse the repository at this point in the history
* Migrating to the proper base namespace

* Fix logic for selecting base namespace

* Include a note about psr-4
  • Loading branch information
srtfisher authored Aug 1, 2024
1 parent 8e4cfae commit 6656219
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 39 deletions.
1 change: 1 addition & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<properties>
<property name="prefixes" type="array">
<element value="vendor_name" />
<element value="alley" />
<element value="create_wordpress_plugin" />
</property>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion .scaffolder/plugin-feature/feature.php.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Create_WordPress_Plugin
*/

namespace Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Features" }};
namespace Alley\WP\Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Features" }};

use Alley\WP\Types\Feature;

Expand Down
2 changes: 1 addition & 1 deletion .scaffolder/plugin-feature/test.php.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Tests\Features" }};
namespace Alley\WP\Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Tests\Features" }};

use Create_WordPress_Plugin\Tests\TestCase;
use Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Features" }}\\{{ wpClassName inputs.featureName }};
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MAKEFLAGS += --no-builtin-rules

setup:
php ./configure.php

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Run `npm run lint` to run ESLint against all JavaScript files. Linting will also
happen when running development or production builds.

Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.
Unit testing code is written in PSR-4 format and can be found in the `tests`
directory.

### The `entries` directory and entry points

Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@
},
"autoload-dev": {
"psr-4": {
"Create_WordPress_Plugin\\Tests\\": "tests"
"Alley\\WP\\Create_WordPress_Plugin\\Tests\\": "tests"
}
},
"extra": {
"wordpress-autoloader": {
"autoload": {
"Create_WordPress_Plugin\\": "src"
},
"autoload-dev": {
"Create_WordPress_Plugin\\Tests\\": "tests"
"Alley\\WP\\Create_WordPress_Plugin\\": "src"
}
}
},
Expand Down
29 changes: 7 additions & 22 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* phpcs:disable
*/

namespace Create_WordPress_Plugin\Configure;
namespace Alley\WP\Create_WordPress_Plugin\Configure;

if ( ! defined( 'STDIN' ) ) {
die( 'Not in CLI mode.' );
Expand Down Expand Up @@ -478,7 +478,7 @@ function enable_sqlite_testing(): void {
while ( true ) {
$plugin_name_slug = slugify( ask(
question: 'Plugin slug?',
default: slugify( $plugin_name ),
default: 'wp-' . ltrim( slugify( $plugin_name ), 'wp-' ),
allow_empty: false,
) );

Expand Down Expand Up @@ -514,8 +514,8 @@ function enable_sqlite_testing(): void {
$example_namespace = 'Alley\\WP\\' . title_case( $plugin_name );
contributing_message( "Alley WordPress plugins should be prefixed with \"Alley\\WP\\\". A namespace such as \"{$example_namespace}\" would work well. If this plugin isn't meant to be published anywhere, this is fine to ignore. See our CONTRIBUTING.md for more details." );

if ( confirm( 'Do you wish to continue anyway?', false ) ) {
break;
if ( ! confirm( 'Do you wish to continue anyway?', false ) ) {
continue;
}
}

Expand Down Expand Up @@ -566,13 +566,11 @@ function enable_sqlite_testing(): void {

'A skeleton WordPress plugin' => $description,

// Escape the namespace used in composer.json.
'"Create_WordPress_Plugin\\"' => (string) json_encode( $namespace ),
'"Create_WordPress_Plugin\\Tests\\"' => (string) json_encode( $namespace . '\\Tests' ),
// Extra slashes are here for composer.json.
'Alley\\\WP\\\Create_WordPress_Plugin\\\\' => str_replace( '\\', '\\\\', $namespace ) . '\\\\',
'Alley\WP\Create_WordPress_Plugin' => $namespace,

'Create_WordPress_Plugin' => $namespace,
'Example_Plugin' => $class_name,

'create_wordpress_plugin' => str_replace( '-', '_', $plugin_name_slug ),
'plugin_name' => $plugin_name,

Expand All @@ -586,19 +584,6 @@ function enable_sqlite_testing(): void {
'plugin.php' => $plugin_file,
];

// Patch the Composer.json namespace first before search and replace.
run(
'composer config extra.wordpress-autoloader.autoload --json \'' . json_encode( [
$namespace => 'src',
] ) . '\'',
);

run(
'composer config extra.wordpress-autoloader.autoload-dev --json \'' . json_encode( [
$namespace . '\\Tests' => 'tests',
] ) . '\'',
);

foreach ( list_all_files_for_replacement() as $path ) {
echo "Updating $path...\n";

Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin;
namespace Alley\WP\Create_WordPress_Plugin;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down
2 changes: 1 addition & 1 deletion src/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin;
namespace Alley\WP\Create_WordPress_Plugin;

/**
* Validate file paths to prevent a PHP error if a file doesn't exist.
Expand Down
2 changes: 1 addition & 1 deletion src/class-example-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin;
namespace Alley\WP\Create_WordPress_Plugin;

/**
* Example Plugin
Expand Down
2 changes: 1 addition & 1 deletion src/features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This is a port of the infamous WordPress `hello.php` plugin to a feature. The ly
* @package Create_WordPress_Plugin
*/
namespace Create_WordPress_Plugin\Features;
namespace Alley\WP\Create_WordPress_Plugin\Features;
use Alley\WP\Types\Feature;
Expand Down
2 changes: 1 addition & 1 deletion src/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin;
namespace Alley\WP\Create_WordPress_Plugin;

use Alley\WP\Features\Group;

Expand Down
2 changes: 1 addition & 1 deletion src/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin;
namespace Alley\WP\Create_WordPress_Plugin;

/**
* Register meta for posts or terms with sensible defaults and sanitization.
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/ExampleFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin\Tests\Feature;
namespace Alley\WP\Create_WordPress_Plugin\Tests\Feature;

use Create_WordPress_Plugin\Tests\TestCase;
use Alley\WP\Create_WordPress_Plugin\Tests\TestCase;

/**
* A test suite for an example feature.
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin\Tests;
namespace Alley\WP\Create_WordPress_Plugin\Tests;

use Mantle\Testkit\Test_Case as TestkitTest_Case;

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ExampleUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin\Tests\Unit;
namespace Alley\WP\Create_WordPress_Plugin\Tests\Unit;

use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit 6656219

Please sign in to comment.