Skip to content

Commit

Permalink
Added a grunt task to run phpcs
Browse files Browse the repository at this point in the history
This commit adds a grunt task (named `php`) that will run phpcs with the PSR-2 standard.

Note that you have to install php_codesniffer which has been added as a require-dev lib.

Doing `composer install` will mess up Symphony's auto loader, so please `git checkout vendor` after the composer call
  • Loading branch information
nitriques committed Feb 18, 2016
1 parent 143ae74 commit 22069f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"issues": "https://github.com/symphonycms/symphony-2/issues",
"wiki": "https://github.com/symphonycms/symphony-2/wiki"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*"
},
"minimum-stability": "stable",
"autoload": {
"classmap": ["symphony/content", "symphony/lib", "symphony/template", "install"],
Expand Down
19 changes: 19 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ module.exports = function (grunt) {
scripts: {
files: 'symphony/assets/js/src/*.js',
tasks: ['js']
},
php: {
files: ['symphony/**/*.php', 'install/**/*.php'],
tasks: ['php']
}
},

phpcs: {
application: {
src: ['symphony/**/*.php', 'install/**/*.php', 'index.php']
},
options: {
bin: 'vendor/bin/phpcs',
standard: 'PSR1',
showSniffCodes: true,
tabWidth: 4,
errorSeverity: 10
}
}

Expand All @@ -138,8 +155,10 @@ module.exports = function (grunt) {
//grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-phpcs');

grunt.registerTask('default', ['concat', 'autoprefixer', 'csso', 'uglify']);
grunt.registerTask('css', ['concat', 'autoprefixer', 'csso']);
grunt.registerTask('php', ['phpcs']);
grunt.registerTask('js', ['uglify']);
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"devDependencies": {
"grunt": "~0.4.5",
"grunt-autoprefixer": "~3.0.4",
"grunt-csso": "~0.8.1",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-uglify": "~0.11.1",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-watch": "~0.6.1"
"grunt-contrib-watch": "~0.6.1",
"grunt-csso": "~0.8.1",
"grunt-phpcs": "^0.4.0"
}
}

8 comments on commit 22069f4

@brendo
Copy link
Member

@brendo brendo commented on 22069f4 Feb 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the comment about running composer install. If a new autoloader is generated, why won't it work? AFAIK the only reason we actually commit the /vendor directory is because historically Symphony has been available as a zip and the developer requires minimal dependencies to get it going.

These days, I'm not sure that goal is still relevant. Most developers will be familiar with Composer/Grunt as they are already using them in their everyday workflow.

@nitriques
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a new autoloader is generated, why won't it work?

It deletes the files in the autoload.php file.

@brendo
Copy link
Member

@brendo brendo commented on 22069f4 Feb 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What files in autoload.php? That's an automatically generated file?

@nitriques
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What files in autoload.php? That's an automatically generated file?

No vendor/composer/autoload_classmap.php, vendor/composer/ClassLoader.php and vendor/composer/autoload_files.php

@brendo
Copy link
Member

@brendo brendo commented on 22069f4 Feb 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, there must be some other way to define the classmap, leave it with me, I'll see what I can find :)

@nitriques
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I am still a composer n00b but we really need to embrace it. It's like "doing node" without npm...

@brendo
Copy link
Member

@brendo brendo commented on 22069f4 Feb 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of those files are automatically generated by the composer.json:

    "autoload": {
      "classmap": ["symphony/content", "symphony/lib", "symphony/template", "install"],
      "files": [
        "symphony/lib/boot/func.utilities.php",
        "symphony/lib/boot/defines.php",
        "symphony/lib/toolkit/util.validators.php"
      ]
    }

This will automatically build those files based of the paths and files defined here, so it shouldn't matter that they are blown away each time composer install or composer update is run.

Reference

@nitriques
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. well, thanks then!

Please sign in to comment.