PHP開発環境構築1

PHPの開発環境を手軽に揃えます。

Overview

  • MAMP
  • composer
  • VScode
  • PHPMD
  • PHP Code Sniffer と Beautifier

Input

MAMP
Download Composer Latest: v1.8.4
vscode
PHPMD Version 2.6.0
PHP Code Sniffer
phpcs & phpcbf コマンドについてメモ

Proccess

  1. MAMPDL & install
  2. composerDL & install
  3. vscodeDL & install
  4. PHP Messdetector DL
  5. PHP Code Sniffer / Code Beautifier DL & install

MAMPDL & install

これは普通にインストール

composerDL & install

これは公式サイトのコマンドを順次実行

froggugugugu$ cd /usr/local/bin
froggugugugu$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
froggugugugu$ php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
froggugugugu$ php composer-setup.php
All settings correct for using Composer
Downloading...
Composer (version 1.8.4) successfully installed to: /usr/local/bin/composer.phar
Use it: php composer.phar
froggugugugu$ ls composer.phar
composer.phar
froggugugugu$ mv composer.phar composer
froggugugugu$ composer --version
Composer version 1.8.4 2019-02-11 10:52:10

vscodeDL & install

こちらはDLしてきて 日本語化

PHP Messdetector DL

こちらはcomposerで入れるよりpharがあるので、composer同様に/usr/local/bin配下に入れてパス通して使えるように しちゃいます。

froggugugugu$ cd /usr/local/bin
froggugugugu$ php -r "copy('http://static.phpmd.org/php/2.6.0/phpmd.phar', 'phpmd');"
froggugugugu$ ls -al phpmd
-rw-r--r--  1 froggugugugu  admin  2492072  3 10 22:25 phpmd
froggugugugu$ chmod 755 phpmd
froggugugugu$ ls -al phpmd
-rwxr-xr-x  1 froggugugugu  admin  2492072  3 10 22:25 phpmd
froggugugugu$ phpmd --help
Mandatory arguments:
1) A php source code filename or directory. Can be a comma-separated string
2) A report format
3) A ruleset filename or a comma-separated string of rulesetfilenames

Available formats: xml, text, html.
Available rulesets: cleancode, codesize, controversial, design, naming, unusedcode.

Optional arguments that may be put after the mandatory arguments:
--minimumpriority: rule priority threshold; rules with lower priority than this will not be used
--reportfile: send report output to a file; default to STDOUT
--suffixes: comma-separated string of valid source code filename extensions, e.g. php,phtml
--exclude: comma-separated string of patterns that are used to ignore directories
--strict: also report those nodes with a @SuppressWarnings annotation
--ignore-violations-on-exit: will exit with a zero code, even if any violations are found

PHP Code SnifferDL/ Code Beautifier & install

GithubのInstallation見るとたくさん方法があるのですがこちらも他と同様、pharDLしてきて配置するようにしちゃいます。

froggugugugu$ cd /usr/local/bin/
froggugugugu$ php -r "copy('https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar', 'phpcs');"
froggugugugu$ ls -al phpcs
-rw-r--r--  1 froggugugugu  admin  1172917  3 10 23:14 phpcs
froggugugugu$ chmod 755 phpcs
froggugugugu$ phpcs --version
PHP_CodeSniffer version 3.4.0 (stable) by Squiz (http://www.squiz.net)
froggugugugu$ cd /usr/local/bin/
froggugugugu$ php -r "copy('https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar', 'phpcbf');"
froggugugugu$ ls -al phpcbf
-rw-r--r--  1 froggugugugu  admin  1172921  3 10 23:20 phpcbf
froggugugugu$ chmod 755 phpcbf
froggugugugu$ phpcbf --version
PHP_CodeSniffer version 3.4.0 (stable) by Squiz (http://www.squiz.net)

Output

あとはVSCodeから保存時やらショートカットやらに結びつける


  • ラズパイ_電子工作1 Prev
  • JS開発環境構築1 Next