Docker CodeSniffer - phpcbf 不更改文件

Docker CodeSniffer - phpcbf doesn't change files

您好,我对 phpcbf 有疑问。这是我的 docker 配置:

docker-compose.yml

version: "2"
services:    
    data:
        build: docker/application
        volumes:
            - .:/var/www/html
    fpm:
        build: docker/php-fpm
        volumes_from:
            - data
    nginx:
        build: docker/nginx
        ports:
            - "80:80"
        links:
            - fpm
        volumes_from:
            - data

docker/application/Dockerfile

FROM debian:jessie

ADD ./ /var/www/html

docker/php-fpm/Dockerfile

FROM php:fpm

#Install PHP_CodeSniffer
RUN apt-get update && apt-get install -y wget && apt-get install -y vim && \
    wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && \
    wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar

RUN chmod u+x *.phar

RUN mv phpcbf.phar /usr/local/bin/phpcbf
RUN mv phpcs.phar /usr/local/bin/phpcs

RUN phpcs --config-set default_standard PSR2

RUN apt-get remove -y wget

docker/nginx/Dockerfile

FROM nginx:latest

ADD default.conf /etc/nginx/conf.d/

docker/nginx/default.conf

server {
    listen 80;
    root /var/www/html;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass fpm:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

phpcs index.php - 测试文件

root@6ad6c7f34641:/var/www/html# phpcs index.php                                                                                                                                                        

FILE: /var/www/html/index.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 3 | ERROR | [ ] Each class must be in a namespace of at least one
   |       |     level (a top-level vendor name)
 3 | ERROR | [x] Opening brace of a class must be on the line after
   |       |     the definition
 6 | ERROR | [x] Opening brace should be on a new line
 9 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 48ms; Memory: 4Mb

以及什么都不做的自动修复测试。文件未更改。

root@6ad6c7f34641:/var/www/html# phpcbf index.php                                                                                                                                                          
Changing into directory /var/www/html
Processing index.php [PHP => 47 tokens in 9 lines]... DONE in 8ms (3 fixable violations)
        => Fixing file: 0/3 violations remaining [made 3 passes]... DONE in 4ms 
sh: 1: patch: not found
Array
(
)
Returned: 127
Time: 103ms; Memory: 4Mb

你能帮我看看我错过了什么吗?谢谢

问题已解决:错误表明我没有安装 patch 命令,PHPCBF 使用该命令一次性应用更改。

docker/php-fpm/Dockerfile

FROM php:fpm

RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y vim && \
apt-get install -y patch && \
wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && \
wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar

RUN chmod u+x *.phar

RUN mv phpcbf.phar /usr/local/bin/phpcbf
RUN mv phpcs.phar /usr/local/bin/phpcs

RUN phpcs --config-set default_standard PSR2

RUN apt-get remove -y wget