Drupal 코드의 분석을 허용하기위한 Phpstan의 확장.
Phpstan은 작곡가가 제공 한 자동로드를 사용하여 기호를 발견 할 수 있습니다. 그러나 Drupal은 모듈 및 테마에 대한 자동로드 정보를 제공하지 않습니다. 이 프로젝트는 해당 네임 스페이스를 등록하여 PHPSTAN이 Drupal 코드베이스에서 자동으로 기호를 올바르게 발견 할 수 있도록합니다.
후원 하시겠습니까?
phpstan/extension-installer 사용하는 경우 phpstan.neon 에 자동으로 포함됩니다.
phpstan/extension-installer 사용하지 않으려면 프로젝트의 Phpstan 구성에 extension.neon 포함시킵니다.
includes:
- vendor/mglaman/phpstan-drupal/extension.neon
Drupal 특정 분석 규칙을 포함하려면이 파일을 포함하십시오.
includes:
- vendor/mglaman/phpstan-drupal/rules.neon
Drupal Slack의 토론 또는 #PHPSTAN 채널에 대한 지원을 요청하십시오.
분석에서 테스트를 제외하려면 다음 매개 변수를 추가하십시오
parameters:
excludePaths:
- *Test.php
- *TestBase.php
이 프로젝트는 감가 상각 규칙을 추가하는 phpstan/phpstan-deprecation-rules 에 따라 다릅니다. 우리는 Drupal-specific 부류 스코프 리졸버를 제공합니다.
감가 상각 테스트 만 처리하려면 phpstan.neon 사용하십시오.
parameters:
customRulesetUsed: true
reportUnmatchedIgnoredErrors: false
# Ignore phpstan-drupal extension's rules.
ignoreErrors:
- '#Drupal calls should be avoided in classes, use dependency injection instead#'
- '#Plugin definitions cannot be altered.#'
- '#Missing cache backend declaration for performance.#'
- '#Plugin manager has cache backend specified but does not declare cache tags.#'
includes:
- vendor/mglaman/phpstan-drupal/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
phpstan/extension-installer 사용하는 동안 감가 상각 규칙을 비활성화하려면 다음을 수행 할 수 있습니다.
{
"extra" : {
"phpstan/extension-installer" : {
"ignore" : [
" phpstan/phpstan-deprecation-rules "
]
}
}
} 자세한 내용은 extension-installer ://github.com/phpstensenstaller#ignoring-a-particular-extension을 참조하십시오
@internal 클래스 확장 검사 비활성화 phpstan.neon 에 다음을 추가하여 ClassExtendsInternalClassRule 규칙을 비활성화 할 수 있습니다.
parameters :
drupal :
rules :
classExtendsInternalClassRule : false EntityTypeManagerGetStorageDynamicReturnTypeExtension Service는 동적 반환 유형을 매핑하는 데 도움이됩니다. 이것은 통과 된 엔티티 유형 ID를 검사하고 기본 EntityStorageInterface 외에 알려진 스토리지 클래스를 반환하려고합니다. 기본 매핑은 extension.neon 에서 찾을 수 있습니다. 예를 들어:
parameters:
drupal:
entityMapping:
block:
class: DrupalblockEntityBlock
storage: DrupalCoreConfigEntityConfigEntityStorage
node:
class: DrupalnodeEntityNode
storage: DrupalnodeNodeStorage
taxonomy_term:
class: DrupaltaxonomyEntityTerm
storage: DrupaltaxonomyTermStorage
user:
class: DrupaluserEntityUser
storage: DrupaluserUserStorage
사용자 정의 엔티티에 대한 지원을 추가하려면 프로젝트의 phpstan.neon 에 동일한 정의를 추가 할 수 있습니다. 검색 API에 대한 매핑을 추가하려면 다음 예제를 참조하십시오.
parameters:
drupal:
entityMapping:
search_api_index:
class: Drupalsearch_apiEntityIndex
storage: Drupalsearch_apiEntitySearchApiConfigEntityStorage
search_api_server:
class: Drupalsearch_apiEntityServer
storage: Drupalsearch_apiEntitySearchApiConfigEntityStorage
마찬가지로 EntityStorageDynamicReturnTypeExtension Service는 엔티티 스토리지를 사용할 때로드, 생성 등의 엔티티의 유형을 결정하는 데 도움이됩니다. 예를 들어 사용할 때
$ node = Drupal:: entityTypeManager ()-> getStorage ( ' node ' )-> create ([ ' type ' => ' page ' , ' title ' => ' foo ' ]); $node 변수의 유형이 DrupalnodeEntityNode 인지 아는 데 도움이됩니다.
기본 매핑은 extension.neon 에서 찾을 수 있습니다 .neon :
parameters :
drupal :
entityMapping :
block :
class : DrupalblockEntityBlock
storage : DrupalCoreConfigEntityConfigEntityStorage
node :
class : DrupalnodeEntityNode
storage : DrupalnodeNodeStorage
taxonomy_term :
class : DrupaltaxonomyEntityTerm
storage : DrupaltaxonomyTermStorage
user :
class : DrupaluserEntityUser
storage : DrupaluserUserStorage 사용자 정의 엔티티에 대한 지원을 추가하려면 프로젝트의 phpstan.neon 에 동일한 정의를 추가 할 수 있습니다.
기여한 모듈은 phpstan/extension-installer 사용할 때 사용자의 코드베이스에 자동으로 등록 할 수있는 자체 매핑을 제공 할 수 있습니다. 확장자 설치 프로그램은 설치된 패키지의 composer.json extra.phpstan 의 값으로 스캔했습니다. 엔터티 매핑 구성이 포함 된 정의 된 포함 포함에 자동으로 번들이됩니다.
예를 들어, 단락 모듈에는 다음 entity_mapping.neon 파일이있을 수 있습니다.
parameters :
drupal :
entityMapping :
paragraph :
class : DrupalparagraphsEntityParagraph
paragraphs_type :
class : DrupalparagraphsEntityParagraphsType 그런 다음 단락의 composer.json 에서 entity_mapping.neon 은 phpstan에 포함됩니다.
{
"name" : " drupal/paragraphs " ,
"description" : " Enables the creation of Paragraphs entities. " ,
"type" : " drupal-module " ,
"license" : " GPL-2.0-or-later " ,
"require" : {
"drupal/entity_reference_revisions" : " ~1.3 "
},
"extra" : {
"phpstan" : {
"includes" : [
" entity_mapping.neon "
]
}
}
}