Skip to content

Commit e6ce6fa

Browse files
authored
Merge pull request #19 from deliciousbrains/18-coding-standards
2 parents 3d4e7c4 + a5e69d7 commit e6ce6fa

File tree

7 files changed

+79
-33
lines changed

7 files changed

+79
-33
lines changed

app/App.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
<?php
2+
/**
3+
* Class to initialize the application
4+
*/
25

36
namespace DeliciousBrains\SpinupWPComposerSite;
47

8+
/**
9+
* App class to initialize the application
10+
*/
511
class App {
612

713
/**
8-
* Load custom site code
14+
* Load custom site code
915
*/
1016
public function register() {
1117
}
1218

1319
/**
1420
* Helper for defining constants if not already defined.
1521
*
16-
* @param string $key
17-
* @param mixed $value
22+
* @param string $key The name of the constant to define
23+
* @param mixed $value The value to give the constant
1824
*/
1925
public static function define( $key, $value ) {
2026
if ( defined( $key ) ) {
@@ -25,8 +31,10 @@ public static function define( $key, $value ) {
2531
}
2632

2733
/**
28-
* @param $name
29-
* @param $arguments
34+
* This allows the environment to be queried using magic methods like App::is_env_<environment>
35+
*
36+
* @param string $name The name of the magic method
37+
* @param array $arguments The arguments to the magic method
3038
*
3139
* @return bool
3240
*/
@@ -36,4 +44,4 @@ public static function __callStatic( $name, $arguments ) {
3644
return $env === env( 'WP_ENV' );
3745
}
3846
}
39-
}
47+
}

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"sort-packages": true,
2525
"allow-plugins": {
2626
"composer/installers": true,
27-
"johnpbloch/wordpress-core-installer": true
27+
"johnpbloch/wordpress-core-installer": true,
28+
"dealerdirect/phpcodesniffer-composer-installer": true
2829
}
2930
},
3031
"require": {
@@ -52,5 +53,8 @@
5253
},
5354
"autoload": {
5455
"psr-4": {"DeliciousBrains\\SpinupWPComposerSite\\": "app/"}
56+
},
57+
"require-dev": {
58+
"humanmade/coding-standards": "^1.1"
5559
}
5660
}

config/app.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* Your base production configuration goes in this file. Environment-specific
54
* overrides go in their respective config/environments/{{WP_ENV}}.php file.
@@ -9,7 +8,7 @@
98
* can.
109
*/
1110

12-
use \DeliciousBrains\SpinupWPComposerSite\App;
11+
use DeliciousBrains\SpinupWPComposerSite\App;
1312

1413
$root_dir = dirname( __DIR__ );
1514
$webroot_dir = $root_dir . '/public';
@@ -23,7 +22,7 @@
2322
* Use Dotenv to set required environment variables and load .env file in root
2423
*/
2524
$env_files = file_exists( $root_dir . '/.env.local' ) ? [ '.env', '.env.local' ] : [ '.env' ];
26-
$dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir, $env_files, false);
25+
$dotenv = Dotenv\Dotenv::createUnsafeImmutable( $root_dir, $env_files, false );
2726
if ( file_exists( $root_dir . '/.env' ) ) {
2827
$dotenv->load();
2928
$dotenv->required( [ 'DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL' ] );
@@ -40,36 +39,36 @@
4039
App::define( 'WP_CONTENT_DIR', $webroot_dir . CONTENT_DIR );
4140
App::define( 'WP_CONTENT_URL', WP_HOME . CONTENT_DIR );
4241

43-
App::define('DB_NAME', env('DB_NAME'));
44-
App::define('DB_USER', env('DB_USER'));
45-
App::define('DB_PASSWORD', env('DB_PASSWORD'));
46-
App::define('DB_HOST', env('DB_HOST') ?: 'localhost');
47-
App::define('DB_CHARSET', 'utf8mb4');
48-
App::define('DB_COLLATE', '');
49-
$table_prefix = env('DB_PREFIX') ?: 'wp_';
42+
App::define( 'DB_NAME', env( 'DB_NAME' ) );
43+
App::define( 'DB_USER', env( 'DB_USER' ) );
44+
App::define( 'DB_PASSWORD', env( 'DB_PASSWORD' ) );
45+
App::define( 'DB_HOST', env( 'DB_HOST' ) ?: 'localhost' );
46+
App::define( 'DB_CHARSET', 'utf8mb4' );
47+
App::define( 'DB_COLLATE', '' );
48+
$table_prefix = env( 'DB_PREFIX' ) ?: 'wp_';
5049

5150
// Set other constants from env file.
52-
foreach( array_keys($dotenv->load()) as $key ) {
53-
App::define($key, env( $key ));
51+
foreach ( array_keys( $dotenv->load() ) as $key ) {
52+
App::define( $key, env( $key ) );
5453
}
5554

56-
// Environment config
55+
// Environment config.
5756
$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';
5857
if ( file_exists( $env_config ) ) {
5958
require_once $env_config;
6059
}
6160

62-
App::define('AUTOMATIC_UPDATER_DISABLED', true);
63-
App::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
64-
// Disable the plugin and theme file editor in the admin
65-
App::define('DISALLOW_FILE_EDIT', true);
66-
// Disable plugin and theme updates and installation from the admin
67-
App::define('DISALLOW_FILE_MODS', true);
61+
App::define( 'AUTOMATIC_UPDATER_DISABLED', true );
62+
App::define( 'DISABLE_WP_CRON', env( 'DISABLE_WP_CRON' ) ?: false );
63+
// Disable the plugin and theme file editor in the admin.
64+
App::define( 'DISALLOW_FILE_EDIT', true );
65+
// Disable plugin and theme updates and installation from the admin.
66+
App::define( 'DISALLOW_FILE_MODS', true );
6867

69-
// Secret keys
68+
// Secret keys.
7069
if ( ! file_exists( __DIR__ . '/keys.php' ) ) {
7170
$keys = file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' );
72-
file_put_contents( __DIR__ . '/keys.php', '<?php use ' . App::class . '; ' . str_replace( 'define(', 'App::define(', $keys ) );
71+
file_put_contents( __DIR__ . '/keys.php', '<?php use ' . App::class . ";\n" . str_replace( 'define(', 'App::define(', $keys ) );
7372
}
7473
include __DIR__ . '/keys.php';
7574

phpcs.xml.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Delicious Brains">
3+
<!-- Files or directories to check -->
4+
<file>.</file>
5+
6+
<!-- Exclude the keys file as this is auto-generated from the WordPress generator -->
7+
<exclude-pattern type="relative-root">^/config/keys.php</exclude-pattern>
8+
9+
<!-- Path to strip from the front of file paths inside reports (displays shorter paths) -->
10+
<arg name="basepath" value="." />
11+
12+
<!-- Use HM Coding Standards -->
13+
<rule ref="vendor/humanmade/coding-standards">
14+
<!-- Namespace isn't required for all files. -->
15+
<exclude name="HM.Functions.NamespacedFunctions.MissingNamespace" />
16+
<!-- Ignore rule expecting Namespaced directory. -->
17+
<exclude name="HM.Files.NamespaceDirectoryName.NoIncDirectory" />
18+
<!-- File name and class name match is not necessary. -->
19+
<exclude name="HM.Files.ClassFileName.MismatchedName" />
20+
<!-- Ignore class file name rule -->
21+
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
22+
<!-- Ignore rule expecting hyphens in file name. -->
23+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
24+
<!-- Don't require file comment header. -->
25+
<exclude name="Squiz.Commenting.FileComment.Missing" />
26+
</rule>
27+
28+
<!-- Ignore Snake case variables for tests -->
29+
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
30+
<exclude-pattern>/tests/*</exclude-pattern>
31+
</rule>
32+
</ruleset>

public/content/mu-plugins/app.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
2-
// Bootstrap our site code
3-
( new DeliciousBrains\SpinupWPComposerSite\App() )->register();
2+
/**
3+
* Bootstrap our site code
4+
*/
5+
6+
( new DeliciousBrains\SpinupWPComposerSite\App() )->register();

public/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @var bool
1313
*/
14-
define('WP_USE_THEMES', true);
14+
define( 'WP_USE_THEMES', true );
1515

1616
/** Loads the WordPress Environment and Template */
17-
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
17+
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );

public/wp-config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
*/
77
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
88
require_once dirname( __DIR__ ) . '/config/app.php';
9-
require_once ABSPATH . 'wp-settings.php';
9+
require_once ABSPATH . 'wp-settings.php';

0 commit comments

Comments
 (0)