zendframework / zend-coding-standard

Zend Framework Coding Standard
BSD 3-Clause "New" or "Revised" License
35 stars 8 forks source link

Add license sniff and fixes #2

Closed geerteltink closed 6 years ago

geerteltink commented 7 years ago

The test are executed independent of the standard AbstractSniffUnitTest class. That class is only available if PHP_CodeSniffer is downloaded by composer with prefer-source.

Copyright year detection:

Violation detection (when running phpcs):

Fixes (when running phpcbf):

TODO:

Discussion:

geerteltink commented 7 years ago

@weierophinney There is an inconsistency in the copyright line in the license files throughout the components:

Copyright (c) 2015-2016, Zend Technologies USA, Inc. All rights reserved.

Vs

Copyright (c) 2015-2016, Zend Technologies USA, Inc.

All rights reserved.

Also I've tested this against zend-expressive and all source code files are updated as expected. I've only found some issues with updating the copyright date which needs to be fixed.

geerteltink commented 7 years ago

@weierophinney I've ironed out the issues. The dates in COPYING and LICENSE are now updated correctly. And the text in those files are now forced to be the same as the default so we get consistency between all components. So far I've tested zend-expressive and zend-code. In 14 seconds it updated all source files and created COPYING.md.

I've ran into another consistency issue.

Expressive:

/**
 * @see       https://github.com/zendframework/zend-expressive for the canonical source repository
 * @copyright https://github.com/zendframework/zend-expressive/blob/master/COPYING.md Copyright
 * @license   https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
 */

zend-code:

/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

Specifically the extra text and @see Vs @link. This can be fixed as well, but I need to know what the preferred format should be.

EDIT: According to PSR-5 PHPDoc (if it ever gets released), @link is deprecated. I'll enforce the @see tag.

geerteltink commented 7 years ago

Example phpcs.xml config file in a component:

<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
    <!-- Load ruleset -->
    <rule ref="./vendor/zendframework/zend-coding-standard/src/ZendCodingStandard/ruleset.xml"/>

    <!-- Check copyright and license files -->
    <file>./COPYRIGHT.md</file>
    <file>./LICENSE.md</file>
    <!-- Paths to check -->
    <file>./src</file>
    <file>./test</file>

    <!-- Exclude test assets -->
    <exclude-pattern>*/TestAsset/*</exclude-pattern>
</ruleset>

/cc @weierophinney

geerteltink commented 6 years ago

Superseded by #4