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

Add PHPCS as dev dependency #102

Merged
merged 16 commits into from Feb 5, 2017
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -2,4 +2,10 @@
*.sublime-project
*.sublime-workspace

# Dependencies
/node_modules
/vendor
/wp-content

# Logs
npm-debug.log
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -25,4 +25,4 @@ before_script:
- npm install

script:
- echo 'Success'
- npm run lint
14 changes: 14 additions & 0 deletions Gruntfile.js
@@ -1,6 +1,12 @@
/* jshint node:true */
module.exports = function( grunt ) {
grunt.initConfig( {
phpcs: {
'default': {
cmd: './vendor/bin/phpcs',
args: [ '--standard=./phpcs.ruleset.xml', '-p', '-s', '-v', '--extensions=php', '.' ]
}
},
browserify: {
media: {
files: {
Expand Down Expand Up @@ -149,6 +155,14 @@ module.exports = function( grunt ) {
grunt.task.run( '_' + this.nameArgs );
} );

grunt.registerMultiTask( 'phpcs', 'Runs PHP code sniffs.', function() {
grunt.util.spawn({
cmd: this.data.cmd,
args: this.data.args,
opts: { stdio: 'inherit' }
}, this.async() );
});

grunt.registerTask( 'css', [ 'cssmin' ] );
grunt.registerTask( 'js', [ 'browserify', 'jshint', 'concat', 'uglify' ] );
grunt.registerTask( 'i18n', [ 'makepot' ] );
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Expand Up @@ -5,15 +5,18 @@
"homepage": "https://github.com/kucrut/wp-menu-icons",
"license": "GPL-2.0",
"type": "wordpress-plugin",
"require": {
"composer/installers": "~1.0",
"kucrut/icon-picker": "~0.4"
},
"authors": [
{
"name": "Dzikri Aziz",
"email": "kvcrvt@gmail.com",
"homepage": "http://kucrut.org/"
"homepage": "https://kucrut.org/"
}
]
],
"require": {
"composer/installers": "~1.0",
"kucrut/icon-picker": "~0.4"
},
"require-dev": {
"wp-coding-standards/wpcs": "^0.10.0"
}
}
4 changes: 2 additions & 2 deletions includes/front.php
Expand Up @@ -65,7 +65,7 @@ public static function init() {
}

foreach ( Menu_Icons::get( 'types' ) as $type ) {
if ( in_array( $type->id, $active_types ) ) {
if ( in_array( $type->id, $active_types, true ) ) {
self::$icon_types[ $type->id ] = $type;
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ public static function _enqueue_styles() {
'menu-icons-extra',
$extra_stylesheet_uri,
false,
Menu_Icons::version
Menu_Icons::VERSION
);
}

Expand Down
46 changes: 23 additions & 23 deletions includes/library/form-fields.php
Expand Up @@ -142,7 +142,7 @@ final public static function load( $url_path = null ) {
* @param array $field Field array
* @param array $args Extra field arguments
*/
final public static function create( Array $field, $args = array() ) {
final public static function create( array $field, $args = array() ) {
$field = wp_parse_args( $field, self::$defaults['field'] );
if ( ! isset( self::$types[ $field['type'] ] )
|| ! is_subclass_of( self::$types[ $field['type'] ], __CLASS__ )
Expand Down Expand Up @@ -285,7 +285,7 @@ protected function build_attributes( $excludes = array() ) {
$attributes = '';

foreach ( $this->attributes as $key => $value ) {
if ( in_array( $key, $excludes ) ) {
if ( in_array( $key, $excludes, true ) ) {
continue;
}

Expand Down Expand Up @@ -321,9 +321,9 @@ public function description() {
if ( ! empty( $this->field['description'] ) ) {
$tag = ( ! empty( $this->args->inline_description ) ) ? 'span' : 'p';

printf(
printf( // WPCS: XSS ok.
'<%1$s class="description">%2$s</%1$s>',
$tag, // xss ok
$tag,
wp_kses( $this->field['description'], $this->allowed_html )
);
}
Expand All @@ -344,7 +344,7 @@ protected function set_properties() {
$this->field['value'] = '';
}

if ( in_array( $this->field['type'], array( 'text', 'url' ) ) ) {
if ( in_array( $this->field['type'], array( 'text', 'url' ), true ) ) {
if ( ! isset( $this->attributes['class'] ) ) {
$this->attributes['class'] = array();
}
Expand All @@ -359,11 +359,11 @@ protected function set_properties() {


public function render() {
printf(
$this->template, // xss ok
printf( // WPCS: xss ok
$this->template,
esc_attr( $this->field['type'] ),
esc_attr( $this->field['value'] ),
$this->build_attributes() // xss ok
$this->build_attributes()
);
$this->description();
}
Expand All @@ -385,9 +385,9 @@ class Kucrut_Form_Field_Textarea extends Kucrut_Form_Field {


public function render() {
printf(
$this->template, // xss ok
$this->build_attributes(), // xss ok
printf( // WPCS: XSS ok.
$this->template,
$this->build_attributes(),
esc_textarea( $this->field['value'] )
);
}
Expand All @@ -409,18 +409,18 @@ protected function set_properties() {


protected function checked( $value ) {
return checked( in_array( $value, $this->field['value'] ), true, false );
return checked( in_array( $value, $this->field['value'], true ), true, false );
}


public function render() {
foreach ( $this->field['choices'] as $value => $label ) {
printf(
$this->template, // xss ok
$this->field['type'], // xss ok
printf( // WPCS: XSS ok.
$this->template,
$this->field['type'],
esc_attr( $value ),
$this->checked( $value ), // xss ok
$this->build_attributes( 'id' ), // xss ok
$this->checked( $value ),
$this->build_attributes( 'id' ),
esc_html( $label )
);
}
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function set_properties() {


protected function selected( $value ) {
return selected( ( $value == $this->field['value'] ), true, false );
return selected( ( $value === $this->field['value'] ), true, false );
}


Expand All @@ -480,10 +480,10 @@ public function render() {
}
?>
<?php
printf(
$this->template, // xss ok
printf( // WPCS: XSS ok.
$this->template,
esc_attr( $value ),
$this->selected( $value ), // xss ok
$this->selected( $value ),
esc_html( $label )
);
?>
Expand All @@ -507,7 +507,7 @@ protected function set_properties() {


protected function selected( $value ) {
return selected( in_array( $value, $this->field['value'] ), true, false );
return selected( in_array( $value, $this->field['value'], true ), true, false );
}
}

Expand Down Expand Up @@ -557,7 +557,7 @@ public function set_properties() {


public function render() {
wp_dropdown_pages( $this->args->wp_dropdown_pages_args );
wp_dropdown_pages( $this->args->wp_dropdown_pages_args ); // WPCS: XSS ok.
}
}

Expand Down
2 changes: 1 addition & 1 deletion includes/library/functions.php
Expand Up @@ -16,7 +16,7 @@
* @param array $keys Needles
* @return mixed
*/
function kucrut_get_array_value_deep( Array $array, Array $keys ) {
function kucrut_get_array_value_deep( array $array, array $keys ) {
if ( empty( $array ) || empty( $keys ) ) {
return $array;
}
Expand Down
8 changes: 6 additions & 2 deletions includes/meta.php
Expand Up @@ -82,7 +82,9 @@ public static function get( $id, $defaults = array() ) {
}
unset( $value['width'] );

if ( isset( $value['position'] ) && ! in_array( $value['position'], array( 'before', 'after' ) ) ) {
if ( isset( $value['position'] ) &&
! in_array( $value['position'], array( 'before', 'after' ), true )
) {
$value['position'] = $defaults['position'];
}

Expand All @@ -92,7 +94,9 @@ public static function get( $id, $defaults = array() ) {
}

// The values below will NOT be saved
if ( ! empty( $value['icon'] ) && in_array( $value['type'], array( 'image', 'svg' ) ) ) {
if ( ! empty( $value['icon'] ) &&
in_array( $value['type'], array( 'image', 'svg' ), true )
) {
$value['url'] = wp_get_attachment_image_url( $value['icon'], 'thumbnail', false );
}

Expand Down
4 changes: 2 additions & 2 deletions includes/settings.php
Expand Up @@ -660,13 +660,13 @@ public static function _enqueue_assets() {
'menu-icons',
"{$url}css/admin{$suffix}.css",
false,
Menu_Icons::version
Menu_Icons::VERSION
);
wp_enqueue_script(
'menu-icons',
"{$url}js/admin{$suffix}.js",
self::$script_deps,
Menu_Icons::version,
Menu_Icons::VERSION,
true
);

Expand Down
2 changes: 1 addition & 1 deletion menu-icons.php
Expand Up @@ -25,7 +25,7 @@
*/
final class Menu_Icons {

const version = '0.10.2';
const VERSION = '0.10.2';

/**
* Holds plugin data
Expand Down
15 changes: 10 additions & 5 deletions package.json
Expand Up @@ -13,15 +13,16 @@
"devDependencies": {
"grunt": "~0.4.5",
"grunt-browserify": "~4.0.1",
"grunt-contrib-uglify": "~0.9.2",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-compress": "~0.13.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-copy": "~0.8.2",
"grunt-contrib-cssmin": "~0.14.0",
"grunt-contrib-jshint": "~0.11.3",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.9.2",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-copy": "~0.8.2",
"grunt-contrib-compress": "~0.13.0",
"grunt-wp-i18n": "~0.5.3"
},
"keywords": [
Expand All @@ -42,5 +43,9 @@
},
"bugs": {
"url": "https://github.com/kucrut/wp-menu-icons/issues"
},
"scripts": {
"lint:php": "grunt phpcs",
"lint": "npm run lint:php"
}
}
22 changes: 22 additions & 0 deletions phpcs.ruleset.xml
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<ruleset name="Icon Picker Coding Standards">
<config name="installed_paths" value="vendor/wp-coding-standards/wpcs" />

<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="WordPress-VIP">
<!-- ...Except for VIP-specific things -->
<exclude name="WordPress.VIP.FileSystemWritesDisallow" />
<exclude name="WordPress.VIP.RestrictedFunctions" />
<exclude name="WordPress.VIP.RestrictedVariables" />
<exclude name="WordPress.VIP.SuperGlobalInputUsage" />
<exclude name="WordPress.VIP.ValidatedSanitizedInput" />
<exclude name="WordPress.VIP.DirectDatabaseQuery" />
</rule>

<exclude-pattern>*/includes/library/icon-picker/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/wp-content/*</exclude-pattern>
</ruleset>