Skip to content

Commit ff54efd

Browse files
authored
Merge pull request #4 from 26B/feature/laravel-setup
2 parents 35e568f + f53465e commit ff54efd

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,60 @@ And add scripts, to configure `phpcs` correctly upon `composer install`, like th
104104
}
105105
```
106106

107+
### Laravel
108+
109+
#### Automatic Setup
110+
111+
Here, you can also use [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer) to automatically link the Laravel standards to phpcs. Again, make sure `phpcs` is installed locally and so our `pre-commit`. We just need to require [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel) package and we are done:
112+
113+
```bash
114+
composer require --dev emielmolenaar/phpcs-laravel
115+
```
116+
117+
Finally, add the same scripts to configure `phpcs` correctly upon `composer install`:
118+
119+
```json
120+
"scripts": {
121+
"install-codestandards": [
122+
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
123+
],
124+
"post-install-cmd": [
125+
"php-pre-commit",
126+
"@install-codestandards"
127+
]
128+
}
129+
```
130+
131+
#### Manual Setup
132+
133+
A Laravel's coding standard repository that is being updated consistently is [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel). We will now proceed to the configuration (very similar to the *WordPress configuration*). First clone [emielmolenaar/phpcs-laravel](https://github.com/emielmolenaar/phpcs-laravel) repository:
134+
135+
```bash
136+
git clone https://github.com/emielmolenaar/phpcs-laravel.git --branch 2.0
137+
```
138+
139+
Again, tell to `phpcs` where the standards are.
140+
141+
```bash
142+
phpcs --config-set installed_paths /full/path/to/phpcs-laravel
143+
```
144+
145+
Once more, make sure `phpcs` recognises and uses the installed standards:
146+
147+
```bash
148+
$ phpcs -i
149+
The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12 and phpcs-laravel
150+
```
151+
152+
The `--config-show` will give the following output:
153+
154+
```bash
155+
$ phpcs --config-show
156+
Using config file: /full/path/to/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.conf
157+
158+
installed_paths: /full/path/to/phpcs-laravel
159+
```
160+
107161
## Troubleshooting
108162

109163
- If the script is not executable, run the following, where the path is to the composer executable. (If installed globally it should be in `~/.composer/vendor/bin`, otherwise it's in the folder that contains `composer.json`.)

0 commit comments

Comments
 (0)