Skip to content

Commit 4300213

Browse files
committed
Added Phan dev-dependency
- Updated composer.json - Created Phan configuration - Updated UXML class
1 parent e255c30 commit 4300213

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

.phan/config.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* This configuration will be read and overlaid on top of the
4+
* default configuration. Command-line arguments will be applied
5+
* after this file is read.
6+
*/
7+
return [
8+
// Supported values: `'5.6'`, `'7.0'`, `'7.1'`, `'7.2'`, `'7.3'`,
9+
// `'7.4'`, `null`.
10+
// If this is set to `null`,
11+
// then Phan assumes the PHP version which is closest to the minor version
12+
// of the php executable used to execute Phan.
13+
//
14+
// Note that the **only** effect of choosing `'5.6'` is to infer
15+
// that functions removed in php 7.0 exist.
16+
// (See `backward_compatibility_checks` for additional options)
17+
// TODO: Set this.
18+
'target_php_version' => null,
19+
20+
// A list of directories that should be parsed for class and
21+
// method information. After excluding the directories
22+
// defined in exclude_analysis_directory_list, the remaining
23+
// files will be statically analyzed for errors.
24+
//
25+
// Thus, both first-party and third-party code being used by
26+
// your application should be included in this list.
27+
'directory_list' => [
28+
'src'
29+
],
30+
31+
// A regex used to match every file name that you want to
32+
// exclude from parsing. Actual value will exclude every
33+
// "test", "tests", "Test" and "Tests" folders found in
34+
// "vendor/" directory.
35+
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
36+
37+
// A directory list that defines files that will be excluded
38+
// from static analysis, but whose class and method
39+
// information should be included.
40+
//
41+
// Generally, you'll want to include the directories for
42+
// third-party code (such as "vendor/") in this list.
43+
//
44+
// n.b.: If you'd like to parse but not analyze 3rd
45+
// party code, directories containing that code
46+
// should be added to both the `directory_list`
47+
// and `exclude_analysis_directory_list` arrays.
48+
'exclude_analysis_directory_list' => [
49+
'vendor/'
50+
],
51+
52+
// Set to true in order to attempt to detect unused variables.
53+
// `dead_code_detection` will also enable unused variable detection.
54+
//
55+
// This has a few known false positives, e.g. for loops or branches.
56+
'unused_variable_detection' => true,
57+
58+
// If enabled, warn about throw statement where the exception types
59+
// are not documented in the PHPDoc of functions, methods, and closures.
60+
'warn_about_undocumented_throw_statements' => true,
61+
62+
// If enabled (and warn_about_undocumented_throw_statements is enabled),
63+
// warn about function/closure/method calls that have (at)throws
64+
// without the invoking method documenting that exception.
65+
'warn_about_undocumented_exceptions_thrown_by_invoked_functions' => true,
66+
67+
// A list of plugin files to execute
68+
// NOTE: values can be the base name without the extension for plugins bundled with Phan (E.g. 'AlwaysReturnPlugin')
69+
// or relative/absolute paths to the plugin (Relative to the project root).
70+
'plugins' => [
71+
'PreferNamespaceUsePlugin',
72+
]
73+
];

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"require": {
2020
"php": ">=7.1",
2121
"lib-libxml": "*"
22+
},
23+
"require-dev": {
24+
"phan/phan": "^3.0"
2225
}
2326
}

src/UXML.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function load(string $xmlString): self {
3636
* @param DOMDocument|null $doc Document instance
3737
* @return self New instamce
3838
*/
39-
public static function newInstance(string $name, ?string $value=null, array $attrs=[], DOMDocument $doc=null) {
39+
public static function newInstance(string $name, ?string $value=null, array $attrs=[], DOMDocument $doc=null): self {
4040
$targetDoc = ($doc === null) ? new DOMDocument() : $doc;
4141
$domElement = $targetDoc->createElement($name, $value);
4242

@@ -57,6 +57,7 @@ public static function newInstance(string $name, ?string $value=null, array $att
5757
/**
5858
* Class constructor
5959
* @param DOMElement $element DOM Element instance
60+
* @suppress PhanUndeclaredProperty
6061
*/
6162
public function __construct(DOMElement $element) {
6263
$this->element = $element;
@@ -114,6 +115,7 @@ public function getAll(string $xpath, ?int $limit=null): array {
114115
$domNodes = $xpathInstance->query($xpath, $this->element);
115116
foreach ($domNodes as $domNode) {
116117
if (!$domNode instanceof DOMElement) continue;
118+
// @phan-suppress-next-line PhanUndeclaredProperty
117119
$res[] = $domNode->uxml ?? new self($domNode);
118120
if (($limit !== null) && (--$limit <= 0)) break;
119121
}

0 commit comments

Comments
 (0)