Automatically create a new laravel project with PHPStan, Easy Coding Standard and IDE Helper (PhpStorm).
- Windows OS
- Laragon (recommended) (laragon.org)
- PHP (included with Laragon)
- pdo-sqlite ext enabled (not enabled, by default. To enable: Laragon menu > PHP > Extensions > tick pdo-sqlite)
- Composer (included with Laragon)
- Git (included with Laragon)
- laravel installer globally installed (
composer global require laravel/installer
) - PhpStorm (recommended), or alternativly VS Code (recommended).
Copy the files from this gist to the following directories:
C:\laragon\usr\bin
(or any directory which is in the Windows PATH Environment variable)
- Project.bat
C:\laragon\usr\share
- .env
- AddScriptsToComposer.php
- ecs.yaml
- phpstan.neon
Note: If laragon is installed to a different location or drive edit Project.bat and
change the line set laragon=c:\laragon
to the location of the laragon directory e.g.
set laragon=d:\laragon
Check Laragon has already been added to the PATH system variable. Laragon menu > Tools > Path > Manage Path. There should be three sections: Lagaon, User and System. Check laragon is added to the user path (do not add twice):
It will look similar to this:
--------------- Laragon ---------------
C:\laragon\bin;
C:\laragon\bin\apache\httpd-2.4.41-win64-VS16\bin;
C:\laragon\bin\code;
C:\laragon\bin\composer;
C:\laragon\bin\git\bin;
C:\laragon\bin\git\cmd;
C:\laragon\bin\git\mingw64\bin;
C:\laragon\bin\git\usr\bin;
C:\laragon\bin\laragon\utils;
C:\laragon\bin\mysql\mysql-5.7.24-winx64\bin;
C:\laragon\bin\nginx\nginx-1.16.0;
C:\laragon\bin\ngrok;
C:\laragon\bin\nodejs\node-v12;
C:\laragon\bin\notepad++;
C:\laragon\bin\php\php-7.4.5-Win32-vc15-x64;
C:\laragon\bin\putty;
C:\laragon\bin\redis\redis-x64-3.2.100;
C:\laragon\bin\telnet;
C:\laragon\usr\bin;
...
--------------- User ---------------
C:\laragon\bin;
C:\laragon\bin\apache\httpd-2.4.41-win64-VS16\bin;
C:\laragon\bin\code;
C:\laragon\bin\composer;
C:\laragon\bin\git\bin;
C:\laragon\bin\git\cmd;
C:\laragon\bin\git\mingw64\bin;
C:\laragon\bin\git\usr\bin;
C:\laragon\bin\laragon\utils;
C:\laragon\bin\mysql\mysql-5.7.24-winx64\bin;
C:\laragon\bin\nginx\nginx-1.16.0;
C:\laragon\bin\ngrok;
C:\laragon\bin\nodejs\node-v12;
C:\laragon\bin\notepad++;
C:\laragon\bin\php\php-7.4.5-Win32-vc15-x64;
C:\laragon\bin\putty;
C:\laragon\bin\redis\redis-x64-3.2.100;
C:\laragon\bin\telnet;
C:\laragon\usr\bin;
...
--------------- System ---------------
%SystemRoot%\system32;
%SystemRoot%;
...
If Laragon is not added to the User path, either use commander from the laragon menu (which will have the PATH automatically added by Laragon), or menu > Add Laragon to Path. You may need to log off and back on for the path to stick.
TL;DR version:
Run:
project.bat
- When prompted type in the name of the Laravel project to be created. e.g. laravel-project
- Wait for the project to be created.
cd
into the project and launch your IDE/code editor.
The windows batch file Project.bat will automatically create a laravel project by taking the following actions:
- Open a command prompt
- Type
Project
- Choose a name for the laravel project
- The directory is checked, if it is existing the batch file will display the error
- laravel new "project" is run
- PHPStan, Easy Coding Standard, IDE Helper (for PHPStorm) are composer required
- git is inisalised and the project files added
- PhpStorm IDE helper files are created
- .editorconfig is appended with:
[*.html]
indent_size = 2
- cc.bat, fc.bat, pu.bat & ps.bat batch files are created for ecs, phpstan and phpunit
- .gitignore is appended with
/.idea
,/report.xml
,/.phpstorm.meta.php
,/_ide_helper.php
and/_ide_helper_models.php
- Base configs files for ECS and PHPStan are copied: ecs.yaml and phpstan.neon
- Scripts are added to composer.json
- git is inisalised, project files added and a base commit created.
- Easy Coding standrd (ECS) is run 10 times
- git add is run again and changed files commited
The project can be started.
Easy Coding Standard (ECS) can be used to check for style and code standards, PSR-12 is used.
To check code, but not fix an errors:
composer check-cs
A Windows batch file has been created, similar to an alias on Linux/Mac (e.g. alias cc="composer check-cs"
), the same
ECS composer check-cs
can be run:
cc
May code fixes are automatically provided by ECS, if advised to run --fix, the following script can be run:
composer fix-cs
A Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. alias fc="composer fix-cs"
), the same
ECS composer fix-cs
can be run:
fc
PHPStan can be used to run static analysis checks:
composer phpstan
The same PHPUnit composer phpstan
can be run:
ps
Happy coding!