Skip to content

Commit 7dd7712

Browse files
committed
Close #13 - Add Phan
1 parent f2193aa commit 7dd7712

File tree

8 files changed

+666
-6
lines changed

8 files changed

+666
-6
lines changed

.phan/config.php

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
<?php
2+
3+
use Phan\Issue;
4+
5+
/**
6+
* This configuration file was automatically generated by 'phan --init --init-level=3'
7+
*
8+
* TODOs (added by 'phan --init'):
9+
*
10+
* - Go through this file and verify that there are no missing/unnecessary files/directories.
11+
* (E.g. this only includes direct composer dependencies - You may have to manually add indirect composer dependencies to 'directory_list')
12+
* - Look at 'plugins' and add or remove plugins if appropriate (see https://github.com/phan/phan/tree/master/.phan/plugins#plugins)
13+
* - Add global suppressions for pre-existing issues to suppress_issue_types (https://github.com/phan/phan/wiki/Tutorial-for-Analyzing-a-Large-Sloppy-Code-Base)
14+
*
15+
* This configuration will be read and overlaid on top of the
16+
* default configuration. Command line arguments will be applied
17+
* after this file is read.
18+
*
19+
* @see src/Phan/Config.php
20+
* See Config for all configurable options.
21+
*
22+
* A Note About Paths
23+
* ==================
24+
*
25+
* Files referenced from this file should be defined as
26+
*
27+
* ```
28+
* Config::projectPath('relative_path/to/file')
29+
* ```
30+
*
31+
* where the relative path is relative to the root of the
32+
* project which is defined as either the working directory
33+
* of the phan executable or a path passed in via the CLI
34+
* '-d' flag.
35+
*/
36+
return [
37+
38+
// Supported values: `'5.6'`, `'7.0'`, `'7.1'`, `'7.2'`, `'7.3'`, `null`.
39+
// If this is set to `null`,
40+
// then Phan assumes the PHP version which is closest to the minor version
41+
// of the php executable used to execute Phan.
42+
//
43+
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
44+
// (See `backward_compatibility_checks` for additional options)
45+
// TODO: Choose a target_php_version for this project, or leave as null and remove this comment
46+
'target_php_version' => NULL,
47+
48+
// If enabled, missing properties will be created when
49+
// they are first seen. If false, we'll report an
50+
// error message if there is an attempt to write
51+
// to a class property that wasn't explicitly
52+
// defined.
53+
'allow_missing_properties' => false,
54+
55+
// If enabled, null can be cast to any type and any
56+
// type can be cast to null. Setting this to true
57+
// will cut down on false positives.
58+
'null_casts_as_any_type' => false,
59+
60+
// If enabled, allow null to be cast as any array-like type.
61+
//
62+
// This is an incremental step in migrating away from `null_casts_as_any_type`.
63+
// If `null_casts_as_any_type` is true, this has no effect.
64+
'null_casts_as_array' => true,
65+
66+
// If enabled, allow any array-like type to be cast to null.
67+
// This is an incremental step in migrating away from `null_casts_as_any_type`.
68+
// If `null_casts_as_any_type` is true, this has no effect.
69+
'array_casts_as_null' => true,
70+
71+
// If enabled, scalars (int, float, bool, string, null)
72+
// are treated as if they can cast to each other.
73+
// This does not affect checks of array keys. See `scalar_array_key_cast`.
74+
'scalar_implicit_cast' => false,
75+
76+
// If enabled, any scalar array keys (int, string)
77+
// are treated as if they can cast to each other.
78+
// E.g. `array<int,stdClass>` can cast to `array<string,stdClass>` and vice versa.
79+
// Normally, a scalar type such as int could only cast to/from int and mixed.
80+
'scalar_array_key_cast' => true,
81+
82+
// If this has entries, scalars (int, float, bool, string, null)
83+
// are allowed to perform the casts listed.
84+
//
85+
// E.g. `['int' => ['float', 'string'], 'float' => ['int'], 'string' => ['int'], 'null' => ['string']]`
86+
// allows casting null to a string, but not vice versa.
87+
// (subset of `scalar_implicit_cast`)
88+
'scalar_implicit_partial' => [],
89+
90+
// If enabled, Phan will warn if **any** type in a method invocation's object
91+
// is definitely not an object,
92+
// or if **any** type in an invoked expression is not a callable.
93+
// Setting this to true will introduce numerous false positives
94+
// (and reveal some bugs).
95+
'strict_method_checking' => true,
96+
97+
// If enabled, Phan will warn if **any** type in the argument's union type
98+
// cannot be cast to a type in the parameter's expected union type.
99+
// Setting this to true will introduce numerous false positives
100+
// (and reveal some bugs).
101+
'strict_param_checking' => false,
102+
103+
// If enabled, Phan will warn if **any** type in a returned value's union type
104+
// cannot be cast to the declared return type.
105+
// Setting this to true will introduce numerous false positives
106+
// (and reveal some bugs).
107+
'strict_return_checking' => true,
108+
109+
// If enabled, Phan will warn if **any** type in a property assignment's union type
110+
// cannot be cast to a type in the property's declared union type.
111+
// Setting this to true will introduce numerous false positives
112+
// (and reveal some bugs).
113+
'strict_property_checking' => true,
114+
115+
// If true, seemingly undeclared variables in the global
116+
// scope will be ignored.
117+
//
118+
// This is useful for projects with complicated cross-file
119+
// globals that you have no hope of fixing.
120+
'ignore_undeclared_variables_in_global_scope' => true,
121+
122+
// Set this to false to emit `PhanUndeclaredFunction` issues for internal functions that Phan has signatures for,
123+
// but aren't available in the codebase, or the internal functions used to run Phan
124+
// (may lead to false positives if an extension isn't loaded)
125+
//
126+
// If this is true(default), then Phan will not warn.
127+
'ignore_undeclared_functions_with_known_signatures' => true,
128+
129+
// Backwards Compatibility Checking. This is slow
130+
// and expensive, but you should consider running
131+
// it before upgrading your version of PHP to a
132+
// new version that has backward compatibility
133+
// breaks.
134+
//
135+
// If you are migrating from PHP 5 to PHP 7,
136+
// you should also look into using
137+
// [php7cc (no longer maintained)](https://github.com/sstalle/php7cc)
138+
// and [php7mar](https://github.com/Alexia/php7mar),
139+
// which have different backwards compatibility checks.
140+
'backward_compatibility_checks' => false,
141+
142+
// If true, check to make sure the return type declared
143+
// in the doc-block (if any) matches the return type
144+
// declared in the method signature.
145+
'check_docblock_signature_return_type_match' => false,
146+
147+
// If true, make narrowed types from phpdoc params override
148+
// the real types from the signature, when real types exist.
149+
// (E.g. allows specifying desired lists of subclasses,
150+
// or to indicate a preference for non-nullable types over nullable types)
151+
//
152+
// Affects analysis of the body of the method and the param types passed in by callers.
153+
//
154+
// (*Requires `check_docblock_signature_param_type_match` to be true*)
155+
'prefer_narrowed_phpdoc_param_type' => true,
156+
157+
// (*Requires `check_docblock_signature_return_type_match` to be true*)
158+
//
159+
// If true, make narrowed types from phpdoc returns override
160+
// the real types from the signature, when real types exist.
161+
//
162+
// (E.g. allows specifying desired lists of subclasses,
163+
// or to indicate a preference for non-nullable types over nullable types)
164+
//
165+
// This setting affects the analysis of return statements in the body of the method and the return types passed in by callers.
166+
'prefer_narrowed_phpdoc_return_type' => true,
167+
168+
// If enabled, check all methods that override a
169+
// parent method to make sure its signature is
170+
// compatible with the parent's.
171+
//
172+
// This check can add quite a bit of time to the analysis.
173+
//
174+
// This will also check if final methods are overridden, etc.
175+
'analyze_signature_compatibility' => true,
176+
177+
// This setting maps case-insensitive strings to union types.
178+
//
179+
// This is useful if a project uses phpdoc that differs from the phpdoc2 standard.
180+
//
181+
// If the corresponding value is the empty string,
182+
// then Phan will ignore that union type (E.g. can ignore 'the' in `@return the value`)
183+
//
184+
// If the corresponding value is not empty,
185+
// then Phan will act as though it saw the corresponding UnionTypes(s)
186+
// when the keys show up in a UnionType of `@param`, `@return`, `@var`, `@property`, etc.
187+
//
188+
// This matches the **entire string**, not parts of the string.
189+
// (E.g. `@return the|null` will still look for a class with the name `the`, but `@return the` will be ignored with the below setting)
190+
//
191+
// (These are not aliases, this setting is ignored outside of doc comments).
192+
// (Phan does not check if classes with these names exist)
193+
//
194+
// Example setting: `['unknown' => '', 'number' => 'int|float', 'char' => 'string', 'long' => 'int', 'the' => '']`
195+
'phpdoc_type_mapping' => [],
196+
197+
// Set to true in order to attempt to detect dead
198+
// (unreferenced) code. Keep in mind that the
199+
// results will only be a guess given that classes,
200+
// properties, constants and methods can be referenced
201+
// as variables (like `$class->$property` or
202+
// `$class->$method()`) in ways that we're unable
203+
// to make sense of.
204+
'dead_code_detection' => false,
205+
206+
// Set to true in order to attempt to detect unused variables.
207+
// `dead_code_detection` will also enable unused variable detection.
208+
//
209+
// This has a few known false positives, e.g. for loops or branches.
210+
'unused_variable_detection' => true,
211+
212+
// If true, this runs a quick version of checks that takes less
213+
// time at the cost of not running as thorough
214+
// of an analysis. You should consider setting this
215+
// to true only when you wish you had more **undiagnosed** issues
216+
// to fix in your code base.
217+
//
218+
// In quick-mode the scanner doesn't rescan a function
219+
// or a method's code block every time a call is seen.
220+
// This means that the problem here won't be detected:
221+
//
222+
// ```php
223+
// <?php
224+
// function test($arg):int {
225+
// return $arg;
226+
// }
227+
// test("abc");
228+
// ```
229+
//
230+
// This would normally generate:
231+
//
232+
// ```
233+
// test.php:3 PhanTypeMismatchReturn Returning type string but test() is declared to return int
234+
// ```
235+
//
236+
// The initial scan of the function's code block has no
237+
// type information for `$arg`. It isn't until we see
238+
// the call and rescan `test()`'s code block that we can
239+
// detect that it is actually returning the passed in
240+
// `string` instead of an `int` as declared.
241+
'quick_mode' => false,
242+
243+
// If true, then before analysis, try to simplify AST into a form
244+
// which improves Phan's type inference in edge cases.
245+
//
246+
// This may conflict with `dead_code_detection`.
247+
// When this is true, this slows down analysis slightly.
248+
//
249+
// E.g. rewrites `if ($a = value() && $a > 0) {...}`
250+
// into `$a = value(); if ($a) { if ($a > 0) {...}}`
251+
'simplify_ast' => true,
252+
253+
// Enable or disable support for generic templated
254+
// class types.
255+
'generic_types_enabled' => true,
256+
257+
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
258+
// Class names should be prefixed with `\`.
259+
//
260+
// (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`)
261+
'globals_type_map' => [],
262+
263+
// The minimum severity level to report on. This can be
264+
// set to `Issue::SEVERITY_LOW`, `Issue::SEVERITY_NORMAL` or
265+
// `Issue::SEVERITY_CRITICAL`. Setting it to only
266+
// critical issues is a good place to start on a big
267+
// sloppy mature code base.
268+
'minimum_severity' => Issue::SEVERITY_LOW,
269+
270+
// Add any issue types (such as `'PhanUndeclaredMethod'`)
271+
// to this black-list to inhibit them from being reported.
272+
'suppress_issue_types' => [],
273+
274+
// A regular expression to match files to be excluded
275+
// from parsing and analysis and will not be read at all.
276+
//
277+
// This is useful for excluding groups of test or example
278+
// directories/files, unanalyzable files, or files that
279+
// can't be removed for whatever reason.
280+
// (e.g. `'@Test\.php$@'`, or `'@vendor/.*/(tests|Tests)/@'`)
281+
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
282+
283+
// A file list that defines files that will be excluded
284+
// from parsing and analysis and will not be read at all.
285+
//
286+
// This is useful for excluding hopelessly unanalyzable
287+
// files that can't be removed for whatever reason.
288+
'exclude_file_list' => [],
289+
290+
// A directory list that defines files that will be excluded
291+
// from static analysis, but whose class and method
292+
// information should be included.
293+
//
294+
// Generally, you'll want to include the directories for
295+
// third-party code (such as "vendor/") in this list.
296+
//
297+
// n.b.: If you'd like to parse but not analyze 3rd
298+
// party code, directories containing that code
299+
// should be added to the `directory_list` as well as
300+
// to `exclude_analysis_directory_list`.
301+
'exclude_analysis_directory_list' => [
302+
'vendor/',
303+
],
304+
305+
// Enable this to enable checks of require/include statements referring to valid paths.
306+
'enable_include_path_checks' => true,
307+
308+
// The number of processes to fork off during the analysis
309+
// phase.
310+
'processes' => 1,
311+
312+
// List of case-insensitive file extensions supported by Phan.
313+
// (e.g. `['php', 'html', 'htm']`)
314+
'analyzed_file_extensions' => [
315+
'php',
316+
],
317+
318+
// You can put paths to stubs of internal extensions in this config option.
319+
// If the corresponding extension is **not** loaded, then Phan will use the stubs instead.
320+
// Phan will continue using its detailed type annotations,
321+
// but load the constants, classes, functions, and classes (and their Reflection types)
322+
// from these stub files (doubling as valid php files).
323+
// Use a different extension from php to avoid accidentally loading these.
324+
// The `tools/make_stubs` script can be used to generate your own stubs (compatible with php 7.0+ right now)
325+
//
326+
// (e.g. `['xdebug' => '.phan/internal_stubs/xdebug.phan_php']`)
327+
'autoload_internal_extension_signatures' => [],
328+
329+
// A list of plugin files to execute.
330+
//
331+
// Plugins which are bundled with Phan can be added here by providing their name (e.g. `'AlwaysReturnPlugin'`)
332+
//
333+
// Documentation about available bundled plugins can be found [here](https://github.com/phan/phan/tree/master/.phan/plugins).
334+
//
335+
// Alternately, you can pass in the full path to a PHP file with the plugin's implementation (e.g. `'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php'`)
336+
'plugins' => [
337+
'AlwaysReturnPlugin',
338+
'PregRegexCheckerPlugin',
339+
'UnreachableCodePlugin',
340+
],
341+
342+
// A list of directories that should be parsed for class and
343+
// method information. After excluding the directories
344+
// defined in `exclude_analysis_directory_list`, the remaining
345+
// files will be statically analyzed for errors.
346+
//
347+
// Thus, both first-party and third-party code being used by
348+
// your application should be included in this list.
349+
'directory_list' => [
350+
'src',
351+
'vendor',
352+
],
353+
354+
// A list of individual files to include in analysis
355+
// with a path relative to the root directory of the
356+
// project.
357+
'file_list' => [
358+
'bin/phpqa-extensions.php',
359+
],
360+
];

.phpqa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ tool:
22
phpa: MacFJA\PHPQAExtensions\Tools\Analyzer\PhpAssumptions
33
phpmnd: MacFJA\PHPQAExtensions\Tools\Analyzer\PhpMagicNumber
44
phpca: MacFJA\PHPQAExtensions\Tools\Analyzer\PhpCodeAnalyzer
5+
phan: MacFJA\PHPQAExtensions\Tools\Analyzer\Phan
56
report:
67
phpa: app/report/phpassumptions.xsl
78
phpmnd: app/report/phpmagicnumber.xsl
89
phpca: app/report/php-code-analyzer.xsl
10+
phan: app/report/phan.xsl

0 commit comments

Comments
 (0)