pickware / style-guide

How we work with code
0 stars 0 forks source link

Enforce short array syntax for php 5.6 #12

Closed thomasnordquist closed 6 years ago

thomasnordquist commented 7 years ago

Since we use different syntax for different php versions it would be nice if we could configure our phpcs.xml

Problem:

I always mix it up, or at least need to look it up

New phpcs.xml

<?xml version="1.0"?>
<ruleset name="ShopwarePlugins">
    <!-- Use the VIISON ruleset installed by composer -->
    <rule ref="./vendor/viison/style-guide/php/php-codesniffer-standard/VIISON/ruleset-5.6.xml">
        <include-pattern>*.php</include-pattern>
    </rule>

    <!-- Exclude all shared dependencies -->
    <exclude-pattern>*/ViisonCommon/*</exclude-pattern>
</ruleset>

Result:

✗ phpcs -n .

FILE: ...cts/shopware-plugins/Community/Core/ViisonPickwareMobile/ViisonPickwareCommon/Classes/Util.php
----------------------------------------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------------------------------------
 146 | ERROR | [x] Short array syntax must be used to define arrays
 198 | ERROR | [x] Short array syntax must be used to define arrays
 218 | ERROR | [x] Short array syntax must be used to define arrays
 238 | ERROR | [x] Short array syntax must be used to define arrays
 241 | ERROR | [x] Short array syntax must be used to define arrays
 274 | ERROR | [x] Short array syntax must be used to define arrays
 277 | ERROR | [x] Short array syntax must be used to define arrays
 288 | ERROR | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------

FILE: ...ore/ViisonPickwareMobile/ViisonPickwareCommon/Controllers/Api/ViisonPickwareCommonVariants.php
----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
 56 | ERROR | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------

FILE: ...reMobile/ViisonPickwareCommon/Controllers/Backend/ViisonPickwareCommonBarcodeLabelPrinting.php
----------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------------------------------------
 517 | ERROR | [x] Short array syntax must be used to define arrays
 546 | ERROR | [x] Short array syntax must be used to define arrays
 921 | ERROR | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------

FILE: ...kwareMobile/ViisonPickwareCommon/Test/Tests/Controllers/Api/ViisonPickwareCommonOrdersTest.php
----------------------------------------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 7 LINES
----------------------------------------------------------------------------------------------------
  27 | ERROR | [x] Short array syntax must be used to define arrays
  62 | ERROR | [x] Short array syntax must be used to define arrays
  88 | ERROR | [x] Short array syntax must be used to define arrays
 127 | ERROR | [x] Short array syntax must be used to define arrays
 168 | ERROR | [x] Short array syntax must be used to define arrays
 205 | ERROR | [x] Short array syntax must be used to define arrays
 216 | ERROR | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------

FILE: ...areMobile/ViisonPickwareCommon/Test/Tests/Controllers/Api/ViisonPickwareCommonVariantsTest.php
----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
 23 | ERROR | [x] Short array syntax must be used to define arrays
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------
svenmuennich commented 7 years ago

I don't think we should have two different rulesets. Can't we subclass that array syntax sniff and enable/disable it conditionally? That way we could add the php compatibility to the plugin's composer.json and read it upon loading the sniff.