diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index becda60..50d0923 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,4 +38,8 @@ jobs: - name: Run PHPCS run: | cd $DRUPAL_ROOT - vendor/bin/phpcs public/themes/contrib/$THEME_NAME --extensions=php,theme,module --standard=Drupal + vendor/bin/phpcs public/themes/contrib/$THEME_NAME --extensions=php,theme,module --standard=Drupal,DrupalPractice + + - name: Run phpstan + working-directory: ${{ env.DRUPAL_ROOT }} + run: vendor/bin/phpstan analyze -c public/themes/contrib/$THEME_NAME/phpstan.neon public/themes/contrib/$THEME_NAME diff --git a/hdbt_admin.theme b/hdbt_admin.theme index 5aa4362..c6753be 100644 --- a/hdbt_admin.theme +++ b/hdbt_admin.theme @@ -5,6 +5,7 @@ * Contains HDBT Admin theme. */ +use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\media\MediaInterface; @@ -118,8 +119,11 @@ function hdbt_admin_form_node_form_alter(&$form, FormStateInterface $form_state, hdbt_admin_apply_form_theme($form); // Get current entity. + $formObject = $form_state->getFormObject(); + assert($formObject instanceof EntityFormInterface); + /** @var \Drupal\node\NodeInterface $node */ - $node = $form_state->getFormObject()->getEntity(); + $node = $formObject->getEntity(); // Disable "Preview" button on new nodes. if ($node->isNew()) { @@ -396,6 +400,7 @@ function hdbt_admin_preprocess_media(&$variables) { } if ($variables['media']->hasTranslation($current_language)) { + // @phpstan-ignore-next-line $alt = $variables['media'] ->getTranslation($current_language)->field_media_image->alt; $variables['alt_text'] = $alt !== '""' ? $alt : FALSE; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..582bde0 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +parameters: + fileExtensions: + - php + - module + - install + - theme + paths: + - ./ + excludePaths: + - vendor + level: 3 + checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false