'', 'removed' => '', 'alternative' => '', ]; foreach ($itemArray as $version => $removed) { if (isset($itemArray['alternative']) === true) { $versionInfo['alternative'] = (string) $itemArray['alternative']; } if (\preg_match('`^\d\.\d(\.\d{1,2})?$`', $version) !== 1) { // Not a version key. continue; } if ($removed === true && $versionInfo['removed'] === '') { $versionInfo['removed'] = $version; } elseif ($removed === false && $versionInfo['deprecated'] === '') { $versionInfo['deprecated'] = $version; } } return $versionInfo; } /** * Convenience method to retrieve the information to be passed to a call to the PHPCS native * `addError()` or `addWarning()` methods in a simple organized array. * * @param string $itemName Item name, normally name of the function or class detected. * @param string $itemBaseCode The basis for the error code. * @param string[] $versionInfo Array of version info as received from the getVersionInfo() method. * * @return array */ protected function getMessageInfo($itemName, $itemBaseCode, array $versionInfo) { $message = $this->msgTemplate; $errorCode = MessageHelper::stringToErrorCode($itemBaseCode, true); $data = [$itemName]; if ($versionInfo['deprecated'] !== '') { $message .= 'deprecated since PHP %s and '; $errorCode .= 'Deprecated'; $data[] = $versionInfo['deprecated']; } if ($versionInfo['removed'] !== '') { $message .= 'removed since PHP %s and '; $errorCode .= 'Removed'; $data[] = $versionInfo['removed']; } // Remove the last 'and' from the message. $message = \substr($message, 0, (\strlen($message) - 5)); if ($versionInfo['alternative'] !== '') { $message .= $this->alternativeOptionTemplate; $data[] = $versionInfo['alternative']; } return [ 'message' => $message, 'errorcode' => $errorCode, 'data' => $data, ]; } }