NewIniDirectivesSniff.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. <?php
  2. /**
  3. * PHPCompatibility, an external standard for PHP_CodeSniffer.
  4. *
  5. * @package PHPCompatibility
  6. * @copyright 2012-2019 PHPCompatibility Contributors
  7. * @license https://opensource.org/licenses/LGPL-3.0 LGPL3
  8. * @link https://github.com/PHPCompatibility/PHPCompatibility
  9. */
  10. namespace PHPCompatibility\Sniffs\IniDirectives;
  11. use PHPCompatibility\AbstractNewFeatureSniff;
  12. use PHP_CodeSniffer_File as File;
  13. /**
  14. * Detect the use of new INI directives through `ini_set()` or `ini_get()`.
  15. *
  16. * PHP version All
  17. *
  18. * @link https://www.php.net/manual/en/ini.list.php
  19. * @link https://www.php.net/manual/en/ini.core.php
  20. *
  21. * @since 5.5
  22. * @since 7.0.7 When a new directive is used with `ini_set()`, the sniff will now throw an error
  23. * instead of a warning.
  24. * @since 7.1.0 Now extends the `AbstractNewFeatureSniff` instead of the base `Sniff` class..
  25. */
  26. class NewIniDirectivesSniff extends AbstractNewFeatureSniff
  27. {
  28. /**
  29. * A list of new INI directives
  30. *
  31. * The array lists : version number with false (not present) or true (present).
  32. * If's sufficient to list the first version where the ini directive appears.
  33. *
  34. * @since 5.5
  35. * @since 7.0.3 Support for 'alternative' has been added.
  36. *
  37. * @var array(string)
  38. */
  39. protected $newIniDirectives = array(
  40. 'auto_globals_jit' => array(
  41. '4.4' => false,
  42. '5.0' => true,
  43. ),
  44. 'com.code_page' => array(
  45. '4.4' => false,
  46. '5.0' => true,
  47. ),
  48. 'date.default_latitude' => array(
  49. '4.4' => false,
  50. '5.0' => true,
  51. ),
  52. 'date.default_longitude' => array(
  53. '4.4' => false,
  54. '5.0' => true,
  55. ),
  56. 'date.sunrise_zenith' => array(
  57. '4.4' => false,
  58. '5.0' => true,
  59. ),
  60. 'date.sunset_zenith' => array(
  61. '4.4' => false,
  62. '5.0' => true,
  63. ),
  64. 'ibase.default_charset' => array(
  65. '4.4' => false,
  66. '5.0' => true,
  67. ),
  68. 'ibase.default_db' => array(
  69. '4.4' => false,
  70. '5.0' => true,
  71. ),
  72. 'mail.force_extra_parameters' => array(
  73. '4.4' => false,
  74. '5.0' => true,
  75. ),
  76. 'mime_magic.debug' => array(
  77. '4.4' => false,
  78. '5.0' => true,
  79. ),
  80. 'mysqli.max_links' => array(
  81. '4.4' => false,
  82. '5.0' => true,
  83. ),
  84. 'mysqli.default_port' => array(
  85. '4.4' => false,
  86. '5.0' => true,
  87. ),
  88. 'mysqli.default_socket' => array(
  89. '4.4' => false,
  90. '5.0' => true,
  91. ),
  92. 'mysqli.default_host' => array(
  93. '4.4' => false,
  94. '5.0' => true,
  95. ),
  96. 'mysqli.default_user' => array(
  97. '4.4' => false,
  98. '5.0' => true,
  99. ),
  100. 'mysqli.default_pw' => array(
  101. '4.4' => false,
  102. '5.0' => true,
  103. ),
  104. 'report_zend_debug' => array(
  105. '4.4' => false,
  106. '5.0' => true,
  107. ),
  108. 'session.hash_bits_per_character' => array(
  109. '4.4' => false,
  110. '5.0' => true,
  111. ),
  112. 'session.hash_function' => array(
  113. '4.4' => false,
  114. '5.0' => true,
  115. ),
  116. 'soap.wsdl_cache_dir' => array(
  117. '4.4' => false,
  118. '5.0' => true,
  119. ),
  120. 'soap.wsdl_cache_enabled' => array(
  121. '4.4' => false,
  122. '5.0' => true,
  123. ),
  124. 'soap.wsdl_cache_ttl' => array(
  125. '4.4' => false,
  126. '5.0' => true,
  127. ),
  128. 'sqlite.assoc_case' => array(
  129. '4.4' => false,
  130. '5.0' => true,
  131. ),
  132. 'tidy.clean_output' => array(
  133. '4.4' => false,
  134. '5.0' => true,
  135. ),
  136. 'tidy.default_config' => array(
  137. '4.4' => false,
  138. '5.0' => true,
  139. ),
  140. 'zend.ze1_compatibility_mode' => array(
  141. '4.4' => false,
  142. '5.0' => true,
  143. ),
  144. 'date.timezone' => array(
  145. '5.0' => false,
  146. '5.1' => true,
  147. ),
  148. 'detect_unicode' => array(
  149. '5.0' => false,
  150. '5.1' => true,
  151. ),
  152. 'fbsql.batchsize' => array(
  153. '5.0' => false,
  154. '5.1' => true,
  155. 'alternative' => 'fbsql.batchSize',
  156. ),
  157. 'realpath_cache_size' => array(
  158. '5.0' => false,
  159. '5.1' => true,
  160. ),
  161. 'realpath_cache_ttl' => array(
  162. '5.0' => false,
  163. '5.1' => true,
  164. ),
  165. 'mbstring.strict_detection' => array(
  166. '5.1.1' => false,
  167. '5.1.2' => true,
  168. ),
  169. 'mssql.charset' => array(
  170. '5.1.1' => false,
  171. '5.1.2' => true,
  172. ),
  173. 'gd.jpeg_ignore_warning' => array(
  174. '5.1.2' => false,
  175. '5.1.3' => true,
  176. ),
  177. 'fbsql.show_timestamp_decimals' => array(
  178. '5.1.4' => false,
  179. '5.1.5' => true,
  180. ),
  181. 'soap.wsdl_cache' => array(
  182. '5.1.4' => false,
  183. '5.1.5' => true,
  184. ),
  185. 'soap.wsdl_cache_limit' => array(
  186. '5.1.4' => false,
  187. '5.1.5' => true,
  188. ),
  189. 'allow_url_include' => array(
  190. '5.1' => false,
  191. '5.2' => true,
  192. ),
  193. 'filter.default' => array(
  194. '5.1' => false,
  195. '5.2' => true,
  196. ),
  197. 'filter.default_flags' => array(
  198. '5.1' => false,
  199. '5.2' => true,
  200. ),
  201. 'pcre.backtrack_limit' => array(
  202. '5.1' => false,
  203. '5.2' => true,
  204. ),
  205. 'pcre.recursion_limit' => array(
  206. '5.1' => false,
  207. '5.2' => true,
  208. ),
  209. 'session.cookie_httponly' => array(
  210. '5.1' => false,
  211. '5.2' => true,
  212. ),
  213. 'cgi.check_shebang_line' => array(
  214. '5.2.0' => false,
  215. '5.2.1' => true,
  216. ),
  217. 'max_input_nesting_level' => array(
  218. '5.2.2' => false,
  219. '5.2.3' => true,
  220. ),
  221. 'mysqli.allow_local_infile' => array(
  222. '5.2.3' => false,
  223. '5.2.4' => true,
  224. ),
  225. 'max_file_uploads' => array(
  226. '5.2.11' => false,
  227. '5.2.12' => true,
  228. ),
  229. 'cgi.discard_path' => array(
  230. '5.2' => false,
  231. '5.3' => true,
  232. ),
  233. 'exit_on_timeout' => array(
  234. '5.2' => false,
  235. '5.3' => true,
  236. ),
  237. 'intl.default_locale' => array(
  238. '5.2' => false,
  239. '5.3' => true,
  240. ),
  241. 'intl.error_level' => array(
  242. '5.2' => false,
  243. '5.3' => true,
  244. ),
  245. 'mail.add_x_header' => array(
  246. '5.2' => false,
  247. '5.3' => true,
  248. ),
  249. 'mail.log' => array(
  250. '5.2' => false,
  251. '5.3' => true,
  252. ),
  253. 'mbstring.http_output_conv_mimetype' => array(
  254. '5.2' => false,
  255. '5.3' => true,
  256. ),
  257. 'mysqli.allow_persistent' => array(
  258. '5.2' => false,
  259. '5.3' => true,
  260. ),
  261. 'mysqli.cache_size' => array(
  262. '5.2' => false,
  263. '5.3' => true,
  264. ),
  265. 'mysqli.max_persistent' => array(
  266. '5.2' => false,
  267. '5.3' => true,
  268. ),
  269. 'mysqlnd.collect_memory_statistics' => array(
  270. '5.2' => false,
  271. '5.3' => true,
  272. ),
  273. 'mysqlnd.collect_statistics' => array(
  274. '5.2' => false,
  275. '5.3' => true,
  276. ),
  277. 'mysqlnd.debug' => array(
  278. '5.2' => false,
  279. '5.3' => true,
  280. ),
  281. 'mysqlnd.net_read_buffer_size' => array(
  282. '5.2' => false,
  283. '5.3' => true,
  284. ),
  285. 'odbc.default_cursortype' => array(
  286. '5.2' => false,
  287. '5.3' => true,
  288. ),
  289. 'request_order' => array(
  290. '5.2' => false,
  291. '5.3' => true,
  292. ),
  293. 'user_ini.cache_ttl' => array(
  294. '5.2' => false,
  295. '5.3' => true,
  296. ),
  297. 'user_ini.filename' => array(
  298. '5.2' => false,
  299. '5.3' => true,
  300. ),
  301. 'zend.enable_gc' => array(
  302. '5.2' => false,
  303. '5.3' => true,
  304. ),
  305. 'curl.cainfo' => array(
  306. '5.3.6' => false,
  307. '5.3.7' => true,
  308. ),
  309. 'max_input_vars' => array(
  310. '5.3.8' => false,
  311. '5.3.9' => true,
  312. ),
  313. 'sqlite3.extension_dir' => array(
  314. '5.3.10' => false,
  315. '5.3.11' => true,
  316. ),
  317. 'cli.pager' => array(
  318. '5.3' => false,
  319. '5.4' => true,
  320. ),
  321. 'cli.prompt' => array(
  322. '5.3' => false,
  323. '5.4' => true,
  324. ),
  325. 'cli_server.color' => array(
  326. '5.3' => false,
  327. '5.4' => true,
  328. ),
  329. 'enable_post_data_reading' => array(
  330. '5.3' => false,
  331. '5.4' => true,
  332. ),
  333. 'mysqlnd.mempool_default_size' => array(
  334. '5.3' => false,
  335. '5.4' => true,
  336. ),
  337. 'mysqlnd.net_cmd_buffer_size' => array(
  338. '5.3' => false,
  339. '5.4' => true,
  340. ),
  341. 'mysqlnd.net_read_timeout' => array(
  342. '5.3' => false,
  343. '5.4' => true,
  344. ),
  345. 'phar.cache_list' => array(
  346. '5.3' => false,
  347. '5.4' => true,
  348. ),
  349. 'session.upload_progress.enabled' => array(
  350. '5.3' => false,
  351. '5.4' => true,
  352. ),
  353. 'session.upload_progress.cleanup' => array(
  354. '5.3' => false,
  355. '5.4' => true,
  356. ),
  357. 'session.upload_progress.name' => array(
  358. '5.3' => false,
  359. '5.4' => true,
  360. ),
  361. 'session.upload_progress.freq' => array(
  362. '5.3' => false,
  363. '5.4' => true,
  364. ),
  365. 'session.upload_progress.min_freq' => array(
  366. '5.3' => false,
  367. '5.4' => true,
  368. ),
  369. 'session.upload_progress.prefix' => array(
  370. '5.3' => false,
  371. '5.4' => true,
  372. ),
  373. 'windows_show_crt_warning' => array(
  374. '5.3' => false,
  375. '5.4' => true,
  376. ),
  377. 'zend.detect_unicode' => array(
  378. '5.3' => false,
  379. '5.4' => true,
  380. 'alternative' => 'detect_unicode',
  381. ),
  382. 'zend.multibyte' => array(
  383. '5.3' => false,
  384. '5.4' => true,
  385. ),
  386. 'zend.script_encoding' => array(
  387. '5.3' => false,
  388. '5.4' => true,
  389. ),
  390. 'zend.signal_check' => array(
  391. '5.3' => false,
  392. '5.4' => true,
  393. ),
  394. 'mysqlnd.log_mask' => array(
  395. '5.3' => false,
  396. '5.4' => true,
  397. ),
  398. 'intl.use_exceptions' => array(
  399. '5.4' => false,
  400. '5.5' => true,
  401. ),
  402. 'mysqlnd.sha256_server_public_key' => array(
  403. '5.4' => false,
  404. '5.5' => true,
  405. ),
  406. 'mysqlnd.trace_alloc' => array(
  407. '5.4' => false,
  408. '5.5' => true,
  409. ),
  410. 'sys_temp_dir' => array(
  411. '5.4' => false,
  412. '5.5' => true,
  413. ),
  414. 'xsl.security_prefs' => array(
  415. '5.4' => false,
  416. '5.5' => true,
  417. ),
  418. 'opcache.enable' => array(
  419. '5.4' => false,
  420. '5.5' => true,
  421. ),
  422. 'opcache.enable_cli' => array(
  423. '5.4' => false,
  424. '5.5' => true,
  425. ),
  426. 'opcache.memory_consumption' => array(
  427. '5.4' => false,
  428. '5.5' => true,
  429. ),
  430. 'opcache.interned_strings_buffer' => array(
  431. '5.4' => false,
  432. '5.5' => true,
  433. ),
  434. 'opcache.max_accelerated_files' => array(
  435. '5.4' => false,
  436. '5.5' => true,
  437. ),
  438. 'opcache.max_wasted_percentage' => array(
  439. '5.4' => false,
  440. '5.5' => true,
  441. ),
  442. 'opcache.use_cwd' => array(
  443. '5.4' => false,
  444. '5.5' => true,
  445. ),
  446. 'opcache.validate_timestamps' => array(
  447. '5.4' => false,
  448. '5.5' => true,
  449. ),
  450. 'opcache.revalidate_freq' => array(
  451. '5.4' => false,
  452. '5.5' => true,
  453. ),
  454. 'opcache.revalidate_path' => array(
  455. '5.4' => false,
  456. '5.5' => true,
  457. ),
  458. 'opcache.save_comments' => array(
  459. '5.4' => false,
  460. '5.5' => true,
  461. ),
  462. 'opcache.load_comments' => array(
  463. '5.4' => false,
  464. '5.5' => true,
  465. ),
  466. 'opcache.fast_shutdown' => array(
  467. '5.4' => false,
  468. '5.5' => true,
  469. ),
  470. 'opcache.enable_file_override' => array(
  471. '5.4' => false,
  472. '5.5' => true,
  473. ),
  474. 'opcache.optimization_level' => array(
  475. '5.4' => false,
  476. '5.5' => true,
  477. ),
  478. 'opcache.inherited_hack' => array(
  479. '5.4' => false,
  480. '5.5' => true,
  481. ),
  482. 'opcache.dups_fix' => array(
  483. '5.4' => false,
  484. '5.5' => true,
  485. ),
  486. 'opcache.blacklist_filename' => array(
  487. '5.4' => false,
  488. '5.5' => true,
  489. ),
  490. 'opcache.max_file_size' => array(
  491. '5.4' => false,
  492. '5.5' => true,
  493. ),
  494. 'opcache.consistency_checks' => array(
  495. '5.4' => false,
  496. '5.5' => true,
  497. ),
  498. 'opcache.force_restart_timeout' => array(
  499. '5.4' => false,
  500. '5.5' => true,
  501. ),
  502. 'opcache.error_log' => array(
  503. '5.4' => false,
  504. '5.5' => true,
  505. ),
  506. 'opcache.log_verbosity_level' => array(
  507. '5.4' => false,
  508. '5.5' => true,
  509. ),
  510. 'opcache.preferred_memory_model' => array(
  511. '5.4' => false,
  512. '5.5' => true,
  513. ),
  514. 'opcache.protect_memory' => array(
  515. '5.4' => false,
  516. '5.5' => true,
  517. ),
  518. 'opcache.mmap_base' => array(
  519. '5.4' => false,
  520. '5.5' => true,
  521. ),
  522. 'opcache.restrict_api' => array(
  523. '5.4' => false,
  524. '5.5' => true,
  525. ),
  526. 'opcache.file_update_protection' => array(
  527. '5.4' => false,
  528. '5.5' => true,
  529. ),
  530. 'opcache.huge_code_pages' => array(
  531. '5.4' => false,
  532. '5.5' => true,
  533. ),
  534. 'opcache.lockfile_path' => array(
  535. '5.4' => false,
  536. '5.5' => true,
  537. ),
  538. 'opcache.opt_debug_level' => array(
  539. '5.4' => false,
  540. '5.5' => true,
  541. ),
  542. 'session.use_strict_mode' => array(
  543. '5.5.1' => false,
  544. '5.5.2' => true,
  545. ),
  546. 'mysqli.rollback_on_cached_plink' => array(
  547. '5.5' => false,
  548. '5.6' => true,
  549. ),
  550. 'assert.exception' => array(
  551. '5.6' => false,
  552. '7.0' => true,
  553. ),
  554. 'pcre.jit' => array(
  555. '5.6' => false,
  556. '7.0' => true,
  557. ),
  558. 'session.lazy_write' => array(
  559. '5.6' => false,
  560. '7.0' => true,
  561. ),
  562. 'zend.assertions' => array(
  563. '5.6' => false,
  564. '7.0' => true,
  565. ),
  566. 'opcache.file_cache' => array(
  567. '5.6' => false,
  568. '7.0' => true,
  569. ),
  570. 'opcache.file_cache_only' => array(
  571. '5.6' => false,
  572. '7.0' => true,
  573. ),
  574. 'opcache.file_cache_consistency_checks' => array(
  575. '5.6' => false,
  576. '7.0' => true,
  577. ),
  578. 'opcache.file_cache_fallback' => array(
  579. '5.6' => false,
  580. '7.0' => true,
  581. ), // Windows only.
  582. 'opcache.validate_permission' => array(
  583. '7.0.13' => false,
  584. '7.0.14' => true,
  585. ),
  586. 'opcache.validate_root' => array(
  587. '7.0.13' => false,
  588. '7.0.14' => true,
  589. ),
  590. 'hard_timeout' => array(
  591. '7.0' => false,
  592. '7.1' => true,
  593. ),
  594. 'session.sid_length' => array(
  595. '7.0' => false,
  596. '7.1' => true,
  597. ),
  598. 'session.sid_bits_per_character' => array(
  599. '7.0' => false,
  600. '7.1' => true,
  601. ),
  602. 'session.trans_sid_hosts' => array(
  603. '7.0' => false,
  604. '7.1' => true,
  605. ),
  606. 'session.trans_sid_tags' => array(
  607. '7.0' => false,
  608. '7.1' => true,
  609. ),
  610. 'url_rewriter.hosts' => array(
  611. '7.0' => false,
  612. '7.1' => true,
  613. ),
  614. // Introduced in PHP 7.1.25, 7.2.13, 7.3.0.
  615. 'imap.enable_insecure_rsh' => array(
  616. '7.1.24' => false,
  617. '7.1.25' => true,
  618. ),
  619. 'syslog.facility' => array(
  620. '7.2' => false,
  621. '7.3' => true,
  622. ),
  623. 'syslog.filter' => array(
  624. '7.2' => false,
  625. '7.3' => true,
  626. ),
  627. 'syslog.ident' => array(
  628. '7.2' => false,
  629. '7.3' => true,
  630. ),
  631. 'session.cookie_samesite' => array(
  632. '7.2' => false,
  633. '7.3' => true,
  634. ),
  635. 'ffi.enable' => array(
  636. '7.3' => false,
  637. '7.4' => true,
  638. ),
  639. 'ffi.preload' => array(
  640. '7.3' => false,
  641. '7.4' => true,
  642. ),
  643. 'opcache.cache_id' => array(
  644. '7.3' => false,
  645. '7.4' => true,
  646. ),
  647. 'opcache.preload' => array(
  648. '7.3' => false,
  649. '7.4' => true,
  650. ),
  651. 'zend.exception_ignore_args' => array(
  652. '7.3' => false,
  653. '7.4' => true,
  654. ),
  655. );
  656. /**
  657. * Returns an array of tokens this test wants to listen for.
  658. *
  659. * @since 5.5
  660. *
  661. * @return array
  662. */
  663. public function register()
  664. {
  665. return array(\T_STRING);
  666. }
  667. /**
  668. * Processes this test, when one of its tokens is encountered.
  669. *
  670. * @since 5.5
  671. *
  672. * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
  673. * @param int $stackPtr The position of the current token in the
  674. * stack passed in $tokens.
  675. *
  676. * @return void
  677. */
  678. public function process(File $phpcsFile, $stackPtr)
  679. {
  680. $tokens = $phpcsFile->getTokens();
  681. $ignore = array(
  682. \T_DOUBLE_COLON => true,
  683. \T_OBJECT_OPERATOR => true,
  684. \T_FUNCTION => true,
  685. \T_CONST => true,
  686. );
  687. $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true);
  688. if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
  689. // Not a call to a PHP function.
  690. return;
  691. }
  692. $functionLc = strtolower($tokens[$stackPtr]['content']);
  693. if (isset($this->iniFunctions[$functionLc]) === false) {
  694. return;
  695. }
  696. $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]);
  697. if ($iniToken === false) {
  698. return;
  699. }
  700. $filteredToken = $this->stripQuotes($iniToken['raw']);
  701. if (isset($this->newIniDirectives[$filteredToken]) === false) {
  702. return;
  703. }
  704. $itemInfo = array(
  705. 'name' => $filteredToken,
  706. 'functionLc' => $functionLc,
  707. );
  708. $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo);
  709. }
  710. /**
  711. * Get the relevant sub-array for a specific item from a multi-dimensional array.
  712. *
  713. * @since 7.1.0
  714. *
  715. * @param array $itemInfo Base information about the item.
  716. *
  717. * @return array Version and other information about the item.
  718. */
  719. public function getItemArray(array $itemInfo)
  720. {
  721. return $this->newIniDirectives[$itemInfo['name']];
  722. }
  723. /**
  724. * Get an array of the non-PHP-version array keys used in a sub-array.
  725. *
  726. * @since 7.1.0
  727. *
  728. * @return array
  729. */
  730. protected function getNonVersionArrayKeys()
  731. {
  732. return array('alternative');
  733. }
  734. /**
  735. * Retrieve the relevant detail (version) information for use in an error message.
  736. *
  737. * @since 7.1.0
  738. *
  739. * @param array $itemArray Version and other information about the item.
  740. * @param array $itemInfo Base information about the item.
  741. *
  742. * @return array
  743. */
  744. public function getErrorInfo(array $itemArray, array $itemInfo)
  745. {
  746. $errorInfo = parent::getErrorInfo($itemArray, $itemInfo);
  747. $errorInfo['alternative'] = '';
  748. if (isset($itemArray['alternative']) === true) {
  749. $errorInfo['alternative'] = $itemArray['alternative'];
  750. }
  751. // Lower error level to warning if the function used was ini_get.
  752. if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') {
  753. $errorInfo['error'] = false;
  754. }
  755. return $errorInfo;
  756. }
  757. /**
  758. * Get the error message template for this sniff.
  759. *
  760. * @since 7.1.0
  761. *
  762. * @return string
  763. */
  764. protected function getErrorMsgTemplate()
  765. {
  766. return "INI directive '%s' is not present in PHP version %s or earlier";
  767. }
  768. /**
  769. * Allow for concrete child classes to filter the error message before it's passed to PHPCS.
  770. *
  771. * @since 7.1.0
  772. *
  773. * @param string $error The error message which was created.
  774. * @param array $itemInfo Base information about the item this error message applies to.
  775. * @param array $errorInfo Detail information about an item this error message applies to.
  776. *
  777. * @return string
  778. */
  779. protected function filterErrorMsg($error, array $itemInfo, array $errorInfo)
  780. {
  781. if ($errorInfo['alternative'] !== '') {
  782. $error .= ". This directive was previously called '%s'.";
  783. }
  784. return $error;
  785. }
  786. /**
  787. * Allow for concrete child classes to filter the error data before it's passed to PHPCS.
  788. *
  789. * @since 7.1.0
  790. *
  791. * @param array $data The error data array which was created.
  792. * @param array $itemInfo Base information about the item this error message applies to.
  793. * @param array $errorInfo Detail information about an item this error message applies to.
  794. *
  795. * @return array
  796. */
  797. protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
  798. {
  799. if ($errorInfo['alternative'] !== '') {
  800. $data[] = $errorInfo['alternative'];
  801. }
  802. return $data;
  803. }
  804. }