Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce static analysis #221

Closed
szepeviktor opened this issue Jan 19, 2020 · 3 comments
Closed

Introduce static analysis #221

szepeviktor opened this issue Jan 19, 2020 · 3 comments
Assignees

Comments

@szepeviktor
Copy link
Contributor

szepeviktor commented Jan 19, 2020

Adding @phpstan to CI is like adding 100 pairs of eyes.

composer require --dev szepeviktor/phpstan-wordpress php-stubs/acf-pro-stubs

phpstan.neon.dist

includes:
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
    level: max
    inferPrivatePropertyTypeFromConstructor: true
    dynamicConstantNames:
        - WP_ENV
    paths:
        - lib/
        - inc/
    autoload_files:
        - vendor/paulthewalton/acf-pro-stubs/acf-pro-stubs.php
        - vendor/twig/twig/src/Extension/CoreExtension.php
        - inc/timberLoader.php
        # Includes
        - inc/baseStyle.php
        - inc/componentLogServer.php
        - inc/fieldVariables.php
        - inc/options.php
        - inc/theContentFix.php
        - inc/tinyMce.php
        - inc/yoastToBottom.php
        - inc/youtubeNoCookieEmbed.php
        # Components
        - Components/BlockCollapse/functions.php
        #- Components/BlockCookieNotice/functions.php
        - Components/BlockImage/functions.php
        - Components/BlockImageText/functions.php
        #- Components/BlockNotFound/functions.php
        #- Components/BlockPostHeader/functions.php
        - Components/BlockVideoOembed/functions.php
        - Components/BlockWysiwyg/functions.php
        - Components/FeatureAdminComponentScreenshots/functions.php
        #- Components/FeatureGoogleAnalytics/functions.php
        - Components/FormPasswordProtection/functions.php
        - Components/GridImageText/functions.php
        #- Components/GridPostsArchive/functions.php
        - Components/GridPostsLatest/functions.php
        - Components/ListComponents/functions.php
        #- Components/ListSearchResults/functions.php
        #- Components/NavigationBurger/functions.php
        #- Components/NavigationFooter/functions.php
        #- Components/NavigationMain/functions.php
        - Components/SliderImages/functions.php
    ignoreErrors:
        # Uses func_get_args()
        - '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'

then run vendor/bin/phpstan analyze -l 4

Please consider reading https://www.php-fig.org/psr/psr-1/#23-side-effects
...which implies loading Components with PSR-4 (aka. Composer loader) and being implemented as classes.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Jan 19, 2020

I suspect Flint is intended for WordPress theme developers who are not really into OOP - although they are really professionals as they earn money by manufacturing themes.

@domtra
Copy link
Member

domtra commented Feb 26, 2020

Hi @szepeviktor,

thanks for bringing this up.

At the moment we are distinguishing most PHP functionality in to two types. One type is PSR-4 auto-loadable and the other always require. The ./lib folder is auto-loaded with PSR-4. Thus this should not have any side-effects. The './inc' folder is basically just an extension of your regular functions.php. Instead of slamming everything in there, we split things up into logically separated files.

Adding php-stan to flynt would be nice, but in a WordPress environment where you have concepts that go against modern PHP ways, you have to do a lot of extra work to reliably use it.

Also, we want to make the barrier of entrance as low as possible. A WordPress developer should not need to learn a new style of coding, just to be able to use our component based approach and enjoy its benefits.

@domtra domtra closed this as completed Feb 26, 2020
@szepeviktor
Copy link
Contributor Author

in a WordPress environment where you have concepts that go against modern PHP ways

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants