Skip to content

Instantly share code, notes, and snippets.

@dantleech
Last active October 21, 2021 21:22

Revisions

  1. dantleech revised this gist Mar 2, 2018. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions phpstan_autoload.php
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,3 @@
    $drupalKernel->boot();

    return $autoload;

    $container = $drupal->boot();

    return $autoload;
  2. dantleech revised this gist Mar 2, 2018. 1 changed file with 14 additions and 6 deletions.
    20 changes: 14 additions & 6 deletions phpstan_autoload.php
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,30 @@
    <?php

    use Drupal\Console\Core\Utils\DrupalFinder;
    use Drupal\Console\Bootstrap\Drupal;
    use Drupal\Console\Application;
    use Drupal\Console\Bootstrap\DrupalKernel;
    use Symfony\Component\HttpFoundation\Request;

    $autoload = require_once __DIR__ . '/autoload.php';

    $root = getcwd();

    $drupalFinder = new DrupalFinder();
    if (!$drupalFinder->locateRoot($root)) {
    echo ('DrupalConsole must be executed within a Drupal Site.');

    exit(1);
    die('DrupalConsole must be executed within a Drupal Site.');
    }

    chdir($drupalFinder->getDrupalRoot());
    $drupal = new Drupal($autoload, $drupalFinder);
    $drupalKernel = DrupalKernel::createFromRequest(
    Request::createFromGlobals(),
    $autoload,
    'prod',
    true,
    $drupalFinder->getDrupalRoot()
    );
    $drupalKernel->boot();

    return $autoload;

    $container = $drupal->boot();

    return $autoload;
  3. dantleech revised this gist Mar 2, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    ```
    $ composer require phpstan/phpstan
    ```

    Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that
    it is fully populated. Note that this may require that the database be accessible (i.e. may be problematic when
    working with Docker). This is why we use a custom autoload file below.

    ```
    $ phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
    $ ./bin/phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
    ```
  4. dantleech revised this gist Mar 2, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that
    it is fully populated. This is why we use a custom autoload file below.
    it is fully populated. Note that this may require that the database be accessible (i.e. may be problematic when
    working with Docker). This is why we use a custom autoload file below.

    ```
    $ phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
  5. dantleech revised this gist Mar 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion phpstan.neon
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    parameters:
    bootstrap: ./docroot/phpstan_autoload.php
    bootstrap: ./docroot/phpstan_autoload.php
  6. dantleech revised this gist Mar 2, 2018. 2 changed files with 6 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions README
    Original file line number Diff line number Diff line change
    @@ -1,6 +0,0 @@
    Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that
    it is fully populated.

    ```
    phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
    ```
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that
    it is fully populated. This is why we use a custom autoload file below.

    ```
    $ phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
    ```
  7. dantleech revised this gist Mar 2, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that
    it is fully populated.

    ```
    phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
    ```
  8. dantleech created this gist Mar 2, 2018.
    2 changes: 2 additions & 0 deletions phpstan.neon
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    parameters:
    bootstrap: ./docroot/phpstan_autoload.php
    22 changes: 22 additions & 0 deletions phpstan_autoload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php

    use Drupal\Console\Core\Utils\DrupalFinder;
    use Drupal\Console\Bootstrap\Drupal;
    use Drupal\Console\Application;

    $autoload = require_once __DIR__ . '/autoload.php';

    $root = getcwd();

    $drupalFinder = new DrupalFinder();
    if (!$drupalFinder->locateRoot($root)) {
    echo ('DrupalConsole must be executed within a Drupal Site.');

    exit(1);
    }

    chdir($drupalFinder->getDrupalRoot());
    $drupal = new Drupal($autoload, $drupalFinder);
    $container = $drupal->boot();

    return $autoload;