-
Notifications
You must be signed in to change notification settings - Fork 666
/
Config.php
2384 lines (1961 loc) · 74 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Psalm;
use Composer\Autoload\ClassLoader;
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\VersionParser;
use DOMDocument;
use DomElement;
use InvalidArgumentException;
use LogicException;
use OutOfBoundsException;
use Psalm\CodeLocation\Raw;
use Psalm\Config\IssueHandler;
use Psalm\Config\ProjectFileFilter;
use Psalm\Config\TaintAnalysisFileFilter;
use Psalm\Exception\ConfigException;
use Psalm\Exception\ConfigNotFoundException;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\Analyzer\FileAnalyzer;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Composer;
use Psalm\Internal\EventDispatcher;
use Psalm\Internal\IncludeCollector;
use Psalm\Internal\Provider\AddRemoveTaints\HtmlFunctionTainter;
use Psalm\Internal\Scanner\FileScanner;
use Psalm\Issue\ArgumentIssue;
use Psalm\Issue\ClassIssue;
use Psalm\Issue\CodeIssue;
use Psalm\Issue\ConfigIssue;
use Psalm\Issue\FunctionIssue;
use Psalm\Issue\MethodIssue;
use Psalm\Issue\PropertyIssue;
use Psalm\Issue\VariableIssue;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Progress\Progress;
use Psalm\Progress\VoidProgress;
use SimpleXMLElement;
use SimpleXMLIterator;
use Throwable;
use UnexpectedValueException;
use Webmozart\PathUtil\Path;
use XdgBaseDir\Xdg;
use stdClass;
use function array_map;
use function array_merge;
use function array_pad;
use function array_pop;
use function array_shift;
use function assert;
use function basename;
use function chdir;
use function class_exists;
use function count;
use function dirname;
use function explode;
use function extension_loaded;
use function file_exists;
use function file_get_contents;
use function filetype;
use function get_class;
use function get_defined_constants;
use function get_defined_functions;
use function getcwd;
use function glob;
use function implode;
use function in_array;
use function is_a;
use function is_dir;
use function is_file;
use function is_string;
use function json_decode;
use function libxml_clear_errors;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function mkdir;
use function phpversion;
use function preg_match;
use function preg_quote;
use function preg_replace;
use function realpath;
use function reset;
use function rmdir;
use function rtrim;
use function scandir;
use function sha1;
use function simplexml_import_dom;
use function str_replace;
use function strlen;
use function strpos;
use function strrpos;
use function strtolower;
use function substr;
use function substr_count;
use function sys_get_temp_dir;
use function trigger_error;
use function unlink;
use function version_compare;
use const DIRECTORY_SEPARATOR;
use const E_USER_ERROR;
use const GLOB_NOSORT;
use const LIBXML_ERR_ERROR;
use const LIBXML_ERR_FATAL;
use const LIBXML_NONET;
use const LIBXML_NOWARNING;
use const PHP_EOL;
use const PHP_VERSION_ID;
use const PSALM_VERSION;
use const SCANDIR_SORT_NONE;
/**
* @psalm-suppress PropertyNotSetInConstructor
* @psalm-consistent-constructor
*/
class Config
{
private const DEFAULT_FILE_NAME = 'psalm.xml';
public const CONFIG_NAMESPACE = 'https://getpsalm.org/schema/config';
public const REPORT_INFO = 'info';
public const REPORT_ERROR = 'error';
public const REPORT_SUPPRESS = 'suppress';
/**
* @var array<string>
*/
public static $ERROR_LEVELS = [
self::REPORT_INFO,
self::REPORT_ERROR,
self::REPORT_SUPPRESS,
];
/**
* @var array
*/
private const MIXED_ISSUES = [
'MixedArgument',
'MixedArrayAccess',
'MixedArrayAssignment',
'MixedArrayOffset',
'MixedArrayTypeCoercion',
'MixedAssignment',
'MixedFunctionCall',
'MixedInferredReturnType',
'MixedMethodCall',
'MixedOperand',
'MixedPropertyFetch',
'MixedPropertyAssignment',
'MixedReturnStatement',
'MixedStringOffsetAssignment',
'MixedArgumentTypeCoercion',
'MixedPropertyTypeCoercion',
'MixedReturnTypeCoercion',
];
/**
* These are special object classes that allow any and all properties to be get/set on them
* @var array<int, class-string>
*/
protected $universal_object_crates = [
stdClass::class,
SimpleXMLElement::class,
SimpleXMLIterator::class,
];
/**
* @var static|null
*/
private static $instance;
/**
* Whether or not to use types as defined in docblocks
*
* @var bool
*/
public $use_docblock_types = true;
/**
* Whether or not to use types as defined in property docblocks.
* This is distinct from the above because you may want to use
* property docblocks, but not function docblocks.
*
* @var bool
*/
public $use_docblock_property_types = false;
/**
* Whether or not to throw an exception on first error
*
* @var bool
*/
public $throw_exception = false;
/**
* Whether or not to load Xdebug stub
*
* @deprecated going to be removed in Psalm 5
*
* @var bool|null
*/
public $load_xdebug_stub;
/**
* The directory to store PHP Parser (and other) caches
*
* @var string|null
*/
public $cache_directory;
/**
* The directory to store all Psalm project caches
*
* @var string|null
*/
public $global_cache_directory;
/**
* Path to the autoader
*
* @var string|null
*/
public $autoloader;
/**
* @var ProjectFileFilter|null
*/
protected $project_files;
/**
* @var ProjectFileFilter|null
*/
protected $extra_files;
/**
* The base directory of this config file
*
* @var string
*/
public $base_dir;
/**
* The PHP version to assume as declared in the config file
*
* @var string|null
*/
private $configured_php_version;
/**
* @var array<int, string>
*/
private $file_extensions = ['php'];
/**
* @var array<string, class-string<FileScanner>>
*/
private $filetype_scanners = [];
/**
* @var array<string, class-string<FileAnalyzer>>
*/
private $filetype_analyzers = [];
/**
* @var array<string, string>
*/
private $filetype_scanner_paths = [];
/**
* @var array<string, string>
*/
private $filetype_analyzer_paths = [];
/**
* @var array<string, IssueHandler>
*/
private $issue_handlers = [];
/**
* @var array<int, string>
*/
private $mock_classes = [];
/**
* @var array<string, string>
*/
private $preloaded_stub_files = [];
/**
* @var array<string, string>
*/
private $stub_files = [];
/**
* @var bool
*/
public $hide_external_errors = false;
/** @var bool */
public $allow_includes = true;
/** @var 1|2|3|4|5|6|7|8 */
public $level = 1;
/**
* @var ?bool
*/
public $show_mixed_issues;
/** @var bool */
public $strict_binary_operands = false;
/**
* @var bool
*/
public $remember_property_assignments_after_call = true;
/** @var bool */
public $use_igbinary = false;
/**
* @var bool
*/
public $allow_phpstorm_generics = false;
/**
* @var bool
*/
public $allow_string_standin_for_class = false;
/**
* @var bool
*/
public $disable_suppress_all = false;
/**
* @var bool
*/
public $use_phpdoc_method_without_magic_or_parent = false;
/**
* @var bool
*/
public $use_phpdoc_property_without_magic_or_parent = false;
/**
* @var bool
*/
public $skip_checks_on_unresolvable_includes = false;
/**
* @var bool
*/
public $seal_all_methods = false;
/**
* @var bool
*/
public $seal_all_properties = false;
/**
* @var bool
*/
public $memoize_method_calls = false;
/**
* @var bool
*/
public $hoist_constants = false;
/**
* @var bool
*/
public $add_param_default_to_docblock_type = false;
/**
* @var bool
*/
public $disable_var_parsing = false;
/**
* @var bool
*/
public $check_for_throws_docblock = false;
/**
* @var bool
*/
public $check_for_throws_in_global_scope = false;
/**
* @var bool
*/
public $ignore_internal_falsable_issues = true;
/**
* @var bool
*/
public $ignore_internal_nullable_issues = true;
/**
* @var array<string, bool>
*/
public $ignored_exceptions = [];
/**
* @var array<string, bool>
*/
public $ignored_exceptions_in_global_scope = [];
/**
* @var array<string, bool>
*/
public $ignored_exceptions_and_descendants = [];
/**
* @var array<string, bool>
*/
public $ignored_exceptions_and_descendants_in_global_scope = [];
/**
* @var bool
*/
public $infer_property_types_from_constructor = true;
/**
* @var bool
*/
public $ensure_array_string_offsets_exist = false;
/**
* @var bool
*/
public $ensure_array_int_offsets_exist = false;
/**
* @var array<lowercase-string, bool>
*/
public $forbidden_functions = [];
/**
* @var bool
*/
public $forbid_echo = false;
/**
* @var bool
*/
public $find_unused_code = false;
/**
* @var bool
*/
public $find_unused_variables = false;
/**
* @var bool
*/
public $find_unused_psalm_suppress = false;
/**
* @var bool
*/
public $run_taint_analysis = false;
/** @var bool */
public $use_phpstorm_meta_path = true;
/**
* @var bool
*/
public $resolve_from_config_file = true;
/**
* @var bool
*/
public $restrict_return_types = false;
/**
* @var bool
*/
public $limit_method_complexity = false;
/**
* @var int
*/
public $max_graph_size = 200;
/**
* @var int
*/
public $max_avg_path_length = 70;
/**
* @var int
*/
public $max_shaped_array_size = 100;
/**
* @var string[]
*/
public $plugin_paths = [];
/**
* @var array<array{class:string,config:?SimpleXMLElement}>
*/
private $plugin_classes = [];
/**
* @var bool
*/
public $allow_internal_named_arg_calls = true;
/**
* @var bool
*/
public $allow_named_arg_calls = true;
/** @var array<string, mixed> */
private $predefined_constants = [];
/** @var array<callable-string, bool> */
private $predefined_functions = [];
/** @var ClassLoader|null */
private $composer_class_loader;
/**
* Custom functions that always exit
*
* @var array<lowercase-string, bool>
*/
public $exit_functions = [];
/**
* @var string
*/
public $hash = '';
/** @var string|null */
public $error_baseline;
/**
* @var bool
*/
public $include_php_versions_in_error_baseline = false;
/** @var string */
public $shepherd_host = 'shepherd.dev';
/**
* @var array<string, string>
*/
public $globals = [];
/**
* @var int
*/
public $max_string_length = 1000;
/** @var ?IncludeCollector */
private $include_collector;
/**
* @var TaintAnalysisFileFilter|null
*/
protected $taint_analysis_ignored_files;
/**
* @var bool whether to emit a backtrace of emitted issues to stderr
*/
public $debug_emitted_issues = false;
/**
* @var bool
*/
private $report_info = true;
/**
* @var EventDispatcher
*/
public $eventDispatcher;
/** @var list<ConfigIssue> */
public $config_issues = [];
/**
* @var 'default'|'never'|'always'
*/
public $trigger_error_exits = 'default';
/**
* @var string[]
*/
public $internal_stubs = [];
/** @var ?int */
public $threads;
protected function __construct()
{
self::$instance = $this;
$this->eventDispatcher = new EventDispatcher();
}
/**
* Gets a Config object from an XML file.
*
* Searches up a folder hierarchy for the most immediate config.
*
* @throws ConfigException if a config path is not found
*
*/
public static function getConfigForPath(string $path, string $current_dir): Config
{
$config_path = self::locateConfigFile($path);
if (!$config_path) {
throw new ConfigNotFoundException('Config not found for path ' . $path);
}
return self::loadFromXMLFile($config_path, $current_dir);
}
/**
* Searches up a folder hierarchy for the most immediate config.
*
* @throws ConfigException
*
*/
public static function locateConfigFile(string $path): ?string
{
$dir_path = realpath($path);
if ($dir_path === false) {
throw new ConfigNotFoundException('Config not found for path ' . $path);
}
if (!is_dir($dir_path)) {
$dir_path = dirname($dir_path);
}
do {
$maybe_path = $dir_path . DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME;
if (file_exists($maybe_path) || file_exists($maybe_path .= '.dist')) {
return $maybe_path;
}
$dir_path = dirname($dir_path);
} while (dirname($dir_path) !== $dir_path);
return null;
}
/**
* Creates a new config object from the file
*/
public static function loadFromXMLFile(string $file_path, string $current_dir): Config
{
$file_contents = file_get_contents($file_path);
$base_dir = dirname($file_path) . DIRECTORY_SEPARATOR;
if ($file_contents === false) {
throw new InvalidArgumentException('Cannot open ' . $file_path);
}
if ($file_contents === '') {
throw new InvalidArgumentException('Invalid empty file ' . $file_path);
}
try {
$config = self::loadFromXML($base_dir, $file_contents, $current_dir, $file_path);
$config->hash = sha1($file_contents . PSALM_VERSION);
} catch (ConfigException $e) {
throw new ConfigException(
'Problem parsing ' . $file_path . ":\n" . ' ' . $e->getMessage()
);
}
return $config;
}
/**
* Computes the hash to use for a cache folder from CLI flags and from the config file's xml contents
*/
public function computeHash(): string
{
return sha1($this->hash . ':' . $this->level);
}
/**
* Creates a new config object from an XML string
* @param string|null $current_dir Current working directory, if different to $base_dir
* @param non-empty-string $file_contents
*
* @throws ConfigException
*/
public static function loadFromXML(
string $base_dir,
string $file_contents,
?string $current_dir = null,
?string $file_path = null
): Config {
if ($current_dir === null) {
$current_dir = $base_dir;
}
self::validateXmlConfig($base_dir, $file_contents);
return self::fromXmlAndPaths($base_dir, $file_contents, $current_dir, $file_path);
}
/**
* @param non-empty-string $file_contents
*/
private static function loadDomDocument(string $base_dir, string $file_contents): DOMDocument
{
$dom_document = new DOMDocument();
// there's no obvious way to set xml:base for a document when loading it from string
// so instead we're changing the current directory instead to be able to process XIncludes
$oldpwd = getcwd();
chdir($base_dir);
$dom_document->loadXML($file_contents, LIBXML_NONET);
$dom_document->xinclude(LIBXML_NOWARNING | LIBXML_NONET);
chdir($oldpwd);
return $dom_document;
}
/**
* @param non-empty-string $file_contents
*
* @throws ConfigException
*/
private static function validateXmlConfig(string $base_dir, string $file_contents): void
{
$schema_path = dirname(__DIR__, 2). '/config.xsd';
if (!file_exists($schema_path)) {
throw new ConfigException('Cannot locate config schema');
}
// Enable user error handling
$prev_xml_internal_errors = libxml_use_internal_errors(true);
libxml_clear_errors();
$dom_document = self::loadDomDocument($base_dir, $file_contents);
$psalm_nodes = $dom_document->getElementsByTagName('psalm');
/** @var DomElement|null */
$psalm_node = $psalm_nodes->item(0);
if (!$psalm_node) {
throw new ConfigException(
'Missing psalm node'
);
}
if (!$psalm_node->hasAttribute('xmlns')) {
$psalm_node->setAttribute('xmlns', self::CONFIG_NAMESPACE);
$old_dom_document = $dom_document;
$old_file_contents = $old_dom_document->saveXML();
assert($old_file_contents !== false && $old_file_contents !== '');
$dom_document = self::loadDomDocument($base_dir, $old_file_contents);
}
$dom_document->schemaValidate($schema_path); // If it returns false it will generate errors handled below
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($prev_xml_internal_errors);
foreach ($errors as $error) {
if ($error->level === LIBXML_ERR_FATAL || $error->level === LIBXML_ERR_ERROR) {
throw new ConfigException(
'Error on line ' . $error->line . ":\n" . ' ' . $error->message
);
}
}
}
/**
* @param positive-int $line_number 1-based line number
* @return int 0-based byte offset
* @throws OutOfBoundsException
*/
private static function lineNumberToByteOffset(string $string, int $line_number): int
{
if ($line_number === 1) {
return 0;
}
$offset = 0;
for ($i = 0; $i < $line_number - 1; $i++) {
$newline_offset = strpos($string, "\n", $offset);
if (false === $newline_offset) {
throw new OutOfBoundsException(
'Line ' . $line_number . ' is not found in a string with ' . ($i + 1) . ' lines'
);
}
$offset = $newline_offset + 1;
}
if ($offset > strlen($string)) {
throw new OutOfBoundsException('Line ' . $line_number . ' is not found');
}
return $offset;
}
private static function processConfigDeprecations(
self $config,
DOMDocument $dom_document,
string $file_contents,
string $config_path
): void {
$config->config_issues = [];
// Attributes to be removed in Psalm 5
$deprecated_attributes = [
'allowCoercionFromStringToClassConst',
'allowPhpStormGenerics',
'forbidEcho',
'loadXdebugStub',
'totallyTyped'
];
$deprecated_elements = [
'exitFunctions',
];
$psalm_element_item = $dom_document->getElementsByTagName('psalm')->item(0);
assert($psalm_element_item !== null);
$attributes = $psalm_element_item->attributes;
foreach ($attributes as $attribute) {
if (in_array($attribute->name, $deprecated_attributes, true)) {
$line = $attribute->getLineNo();
assert($line > 0); // getLineNo() always returns non-zero for nodes loaded from file
$offset = self::lineNumberToByteOffset($file_contents, $line);
$attribute_start = strrpos($file_contents, $attribute->name, $offset - strlen($file_contents)) ?: 0;
$attribute_end = $attribute_start + strlen($attribute->name) - 1;
$config->config_issues[] = new ConfigIssue(
'Attribute "' . $attribute->name . '" is deprecated '
. 'and is going to be removed in the next major version',
new Raw(
$file_contents,
$config_path,
basename($config_path),
$attribute_start,
$attribute_end
)
);
}
}
foreach ($deprecated_elements as $deprecated_element) {
$deprecated_elements_xml = $dom_document->getElementsByTagNameNS(
self::CONFIG_NAMESPACE,
$deprecated_element
);
if ($deprecated_elements_xml->length) {
$deprecated_element_xml = $deprecated_elements_xml->item(0);
assert($deprecated_element_xml !== null);
$line = $deprecated_element_xml->getLineNo();
assert($line > 0);
$offset = self::lineNumberToByteOffset($file_contents, $line);
$element_start = strpos($file_contents, $deprecated_element, $offset) ?: 0;
$element_end = $element_start + strlen($deprecated_element) - 1;
$config->config_issues[] = new ConfigIssue(
'Element "' . $deprecated_element . '" is deprecated '
. 'and is going to be removed in the next major version',
new Raw(
$file_contents,
$config_path,
basename($config_path),
$element_start,
$element_end
)
);
}
}
}
/**
* @param non-empty-string $file_contents
*
* @psalm-suppress MixedMethodCall
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArgument
* @psalm-suppress MixedPropertyFetch
*
* @throws ConfigException
*/
private static function fromXmlAndPaths(
string $base_dir,
string $file_contents,
string $current_dir,
?string $config_path
): self {
$config = new static();
$dom_document = self::loadDomDocument($base_dir, $file_contents);
if (null !== $config_path) {
self::processConfigDeprecations(
$config,
$dom_document,
$file_contents,
$config_path
);
}
$config_xml = simplexml_import_dom($dom_document);
$booleanAttributes = [
'useDocblockTypes' => 'use_docblock_types',
'useDocblockPropertyTypes' => 'use_docblock_property_types',
'throwExceptionOnError' => 'throw_exception',
'hideExternalErrors' => 'hide_external_errors',
'resolveFromConfigFile' => 'resolve_from_config_file',
'allowFileIncludes' => 'allow_includes',
'strictBinaryOperands' => 'strict_binary_operands',
'rememberPropertyAssignmentsAfterCall' => 'remember_property_assignments_after_call',
'disableVarParsing' => 'disable_var_parsing',
'allowPhpStormGenerics' => 'allow_phpstorm_generics',
'allowStringToStandInForClass' => 'allow_string_standin_for_class',
'disableSuppressAll' => 'disable_suppress_all',
'usePhpDocMethodsWithoutMagicCall' => 'use_phpdoc_method_without_magic_or_parent',
'usePhpDocPropertiesWithoutMagicCall' => 'use_phpdoc_property_without_magic_or_parent',
'memoizeMethodCallResults' => 'memoize_method_calls',
'hoistConstants' => 'hoist_constants',
'addParamDefaultToDocblockType' => 'add_param_default_to_docblock_type',
'checkForThrowsDocblock' => 'check_for_throws_docblock',
'checkForThrowsInGlobalScope' => 'check_for_throws_in_global_scope',
'forbidEcho' => 'forbid_echo',
'ignoreInternalFunctionFalseReturn' => 'ignore_internal_falsable_issues',
'ignoreInternalFunctionNullReturn' => 'ignore_internal_nullable_issues',
'includePhpVersionsInErrorBaseline' => 'include_php_versions_in_error_baseline',
'loadXdebugStub' => 'load_xdebug_stub',
'ensureArrayStringOffsetsExist' => 'ensure_array_string_offsets_exist',
'ensureArrayIntOffsetsExist' => 'ensure_array_int_offsets_exist',
'reportMixedIssues' => 'show_mixed_issues',
'skipChecksOnUnresolvableIncludes' => 'skip_checks_on_unresolvable_includes',
'sealAllMethods' => 'seal_all_methods',
'sealAllProperties' => 'seal_all_properties',
'runTaintAnalysis' => 'run_taint_analysis',
'usePhpStormMetaPath' => 'use_phpstorm_meta_path',
'allowInternalNamedArgumentsCalls' => 'allow_internal_named_arg_calls',
'allowNamedArgumentCalls' => 'allow_named_arg_calls',
'findUnusedPsalmSuppress' => 'find_unused_psalm_suppress',
'reportInfo' => 'report_info',
'restrictReturnTypes' => 'restrict_return_types',
'limitMethodComplexity' => 'limit_method_complexity',
'triggerErrorExits' => 'trigger_error_exits',
];
foreach ($booleanAttributes as $xmlName => $internalName) {
if (isset($config_xml[$xmlName])) {
$attribute_text = (string) $config_xml[$xmlName];
$config->setBooleanAttribute(
$internalName,
$attribute_text === 'true' || $attribute_text === '1'
);
}
}
if ($config->resolve_from_config_file) {
$config->base_dir = $base_dir;
} else {
$config->base_dir = $current_dir;
$base_dir = $current_dir;
}
if (isset($config_xml['phpVersion'])) {
$config->configured_php_version = (string) $config_xml['phpVersion'];
}
if (isset($config_xml['autoloader'])) {
$autoloader_path = $config->base_dir . DIRECTORY_SEPARATOR . $config_xml['autoloader'];
if (!file_exists($autoloader_path)) {
throw new ConfigException('Cannot locate autoloader');
}
$config->autoloader = realpath($autoloader_path);
}
if (isset($config_xml['cacheDirectory'])) {
$config->cache_directory = (string)$config_xml['cacheDirectory'];