diff --git a/CHANGELOG/CHANGELOG_v6.md b/CHANGELOG/CHANGELOG_v6.md index a1ad86cd..90ba96d7 100644 --- a/CHANGELOG/CHANGELOG_v6.md +++ b/CHANGELOG/CHANGELOG_v6.md @@ -2,6 +2,8 @@ ## VERSION 6 UNIFIED * Version **6.10** - feat: add methods to get diff statistics + * 2024-03-08 02:00 **6.10.16** fix Differ::getStatistics() + * 297d6a9 fix: Differ::getStatistics() not working when no difference * 2024-03-05 17:05 **6.10.15** new differ option: fullContextIfIdentical * 42dd214 chore: fix php-cs-fixer deprecated options * 239c68f feat: add new differ option: fullContextIfIdentical (#79) diff --git a/example/demo_base.php b/example/demo_base.php index 97170d22..c2a4c47d 100644 --- a/example/demo_base.php +++ b/example/demo_base.php @@ -8,8 +8,8 @@ // the two sample files for comparison $oldFile = __DIR__ . '/old_file.txt'; $newFile = __DIR__ . '/new_file.txt'; -$oldString = \file_get_contents($oldFile); -$newString = \file_get_contents($newFile); +$oldString = file_get_contents($oldFile); +$newString = file_get_contents($newFile); // options for Diff class $diffOptions = [ diff --git a/src/DiffHelper.php b/src/DiffHelper.php index 7c7165fe..1d08cf76 100644 --- a/src/DiffHelper.php +++ b/src/DiffHelper.php @@ -23,7 +23,7 @@ public static function getProjectDirectory(): string { static $path; - return $path = $path ?? \realpath(__DIR__ . '/..'); + return $path = $path ?? realpath(__DIR__ . '/..'); } /** @@ -37,31 +37,31 @@ public static function getRenderersInfo(): array return $info; } - $glob = \implode(\DIRECTORY_SEPARATOR, [ - static::getProjectDirectory(), + $glob = implode(\DIRECTORY_SEPARATOR, [ + self::getProjectDirectory(), 'src', 'Renderer', - '{' . \implode(',', RendererConstant::RENDERER_TYPES) . '}', + '{' . implode(',', RendererConstant::RENDERER_TYPES) . '}', '*.php', ]); - $fileNames = \array_map( + $fileNames = array_map( // get basename without file extension - function (string $file): string { - return \pathinfo($file, \PATHINFO_FILENAME); + static function (string $file): string { + return pathinfo($file, \PATHINFO_FILENAME); }, // paths of all Renderer files - \glob($glob, \GLOB_BRACE) + glob($glob, \GLOB_BRACE) ); - $renderers = \array_filter( + $renderers = array_filter( $fileNames, // only normal class files are wanted - function (string $fileName): bool { + static function (string $fileName): bool { return - \substr($fileName, 0, 8) !== 'Abstract' - && \substr($fileName, -9) !== 'Interface' - && \substr($fileName, -5) !== 'Trait'; + substr($fileName, 0, 8) !== 'Abstract' + && substr($fileName, -9) !== 'Interface' + && substr($fileName, -5) !== 'Trait'; } ); @@ -80,7 +80,7 @@ function (string $fileName): bool { */ public static function getAvailableRenderers(): array { - return \array_keys(self::getRenderersInfo()); + return array_keys(self::getRenderersInfo()); } /** @@ -97,7 +97,7 @@ public static function getStyleSheet(): string return $fileContent; } - $filePath = static::getProjectDirectory() . '/example/diff-table.css'; + $filePath = self::getProjectDirectory() . '/example/diff-table.css'; $file = new \SplFileObject($filePath, 'r'); @@ -133,8 +133,8 @@ public static function calculate( array $rendererOptions = [] ): string { // always convert into array form - \is_string($old) && ($old = \explode("\n", $old)); - \is_string($new) && ($new = \explode("\n", $new)); + \is_string($old) && ($old = explode("\n", $old)); + \is_string($new) && ($new = explode("\n", $new)); return RendererFactory::getInstance($renderer) ->setOptions($rendererOptions) @@ -142,7 +142,8 @@ public static function calculate( Differ::getInstance() ->setOldNew($old, $new) ->setOptions($differOptions) - ); + ) + ; } /** @@ -172,7 +173,7 @@ public static function calculateFiles( $oldFile = new \SplFileObject($old, 'r'); $newFile = new \SplFileObject($new, 'r'); - return static::calculate( + return self::calculate( // fread() requires the length > 0 hence we plus 1 for empty files $oldFile->fread($oldFile->getSize() + 1), $newFile->fread($newFile->getSize() + 1), diff --git a/src/Differ.php b/src/Differ.php index 16d52cd3..3d4df429 100644 --- a/src/Differ.php +++ b/src/Differ.php @@ -185,7 +185,7 @@ public function setNew(array $new): self */ public function setOptions(array $options): self { - $mergedOptions = $options + static::$defaultOptions; + $mergedOptions = $options + self::$defaultOptions; if ($this->options !== $mergedOptions) { $this->options = $mergedOptions; @@ -268,7 +268,7 @@ public static function getInstance(): self { static $singleton; - return $singleton = $singleton ?? new static([], []); + return $singleton = $singleton ?? new self([], []); } /** @@ -334,7 +334,8 @@ public function getGroupedOpcodes(): array } else { $opcodes = $this->sequenceMatcher ->setSequences($old, $new) - ->getGroupedOpcodes($this->options['context']); + ->getGroupedOpcodes($this->options['context']) + ; } $this->getGroupedOpcodesPost($opcodes); @@ -369,7 +370,8 @@ public function getGroupedOpcodesGnu(): array } else { $opcodes = $this->sequenceMatcher ->setSequences($old, $new) - ->getGroupedOpcodes($this->options['context']); + ->getGroupedOpcodes($this->options['context']) + ; } $this->getGroupedOpcodesGnuPost($opcodes); @@ -394,10 +396,10 @@ private function getGroupedOpcodesPre(array &$old, array &$new): void ]; $this->oldSrcLength = \count($old); - \array_push($old, ...$eolAtEofHelperLines); + array_push($old, ...$eolAtEofHelperLines); $this->newSrcLength = \count($new); - \array_push($new, ...$eolAtEofHelperLines); + array_push($new, ...$eolAtEofHelperLines); } /** @@ -517,7 +519,7 @@ private function finalize(): self */ private function resetCachedResults(): self { - foreach (static::CACHED_PROPERTIES as $property => $value) { + foreach (self::CACHED_PROPERTIES as $property => $value) { $this->{$property} = $value; } diff --git a/src/Exception/FileNotFoundException.php b/src/Exception/FileNotFoundException.php index 9a9ed8fb..e9fb0600 100644 --- a/src/Exception/FileNotFoundException.php +++ b/src/Exception/FileNotFoundException.php @@ -6,7 +6,7 @@ final class FileNotFoundException extends \Exception { - public function __construct(string $filepath = '', int $code = 0, \Throwable $previous = null) + public function __construct(string $filepath = '', int $code = 0, ?\Throwable $previous = null) { parent::__construct("File not found: {$filepath}", $code, $previous); } diff --git a/src/Exception/UnsupportedFunctionException.php b/src/Exception/UnsupportedFunctionException.php index e2d4fed5..005c4723 100644 --- a/src/Exception/UnsupportedFunctionException.php +++ b/src/Exception/UnsupportedFunctionException.php @@ -6,7 +6,7 @@ final class UnsupportedFunctionException extends \Exception { - public function __construct(string $funcName = '', int $code = 0, \Throwable $previous = null) + public function __construct(string $funcName = '', int $code = 0, ?\Throwable $previous = null) { parent::__construct("Unsupported function: {$funcName}", $code, $previous); } diff --git a/src/Factory/LineRendererFactory.php b/src/Factory/LineRendererFactory.php index de7438c5..a4fc486b 100644 --- a/src/Factory/LineRendererFactory.php +++ b/src/Factory/LineRendererFactory.php @@ -48,9 +48,9 @@ public static function getInstance(string $type, ...$ctorArgs): AbstractLineRend */ public static function make(string $type, ...$ctorArgs): AbstractLineRenderer { - $className = RendererConstant::RENDERER_NAMESPACE . '\\Html\\LineRenderer\\' . \ucfirst($type); + $className = RendererConstant::RENDERER_NAMESPACE . '\\Html\\LineRenderer\\' . ucfirst($type); - if (!\class_exists($className)) { + if (!class_exists($className)) { throw new \InvalidArgumentException("LineRenderer not found: {$type}"); } diff --git a/src/Factory/RendererFactory.php b/src/Factory/RendererFactory.php index 7f1b1d16..bb6629c1 100644 --- a/src/Factory/RendererFactory.php +++ b/src/Factory/RendererFactory.php @@ -73,7 +73,7 @@ public static function resolveRenderer(string $renderer): ?string foreach (RendererConstant::RENDERER_TYPES as $type) { $className = RendererConstant::RENDERER_NAMESPACE . "\\{$type}\\{$renderer}"; - if (\class_exists($className)) { + if (class_exists($className)) { return $cache[$renderer] = $className; } } diff --git a/src/Renderer/AbstractRenderer.php b/src/Renderer/AbstractRenderer.php index d9e3ec42..8560755a 100644 --- a/src/Renderer/AbstractRenderer.php +++ b/src/Renderer/AbstractRenderer.php @@ -152,8 +152,6 @@ public function getOptions(): array } /** - * {@inheritdoc} - * * @final * * @todo mark this method with "final" in the next major release @@ -176,21 +174,16 @@ public function getResultForIdenticals(): string */ abstract public function getResultForIdenticalsDefault(): string; - /** - * {@inheritdoc} - */ final public function render(Differ $differ): string { $this->changesAreRaw = true; + // the "no difference" situation may happen frequently return $differ->getOldNewComparison() === 0 && !$differ->options['fullContextIfIdentical'] ? $this->getResultForIdenticals() : $this->renderWorker($differ); } - /** - * {@inheritdoc} - */ final public function renderArray(array $differArray): string { $this->changesAreRaw = false; @@ -241,6 +234,6 @@ protected function _(string $text, bool $escapeHtml = true): string { $text = $this->t->translate($text); - return $escapeHtml ? \htmlspecialchars($text) : $text; + return $escapeHtml ? htmlspecialchars($text) : $text; } } diff --git a/src/Renderer/Html/AbstractHtml.php b/src/Renderer/Html/AbstractHtml.php index e4d17701..8e69b0cf 100644 --- a/src/Renderer/Html/AbstractHtml.php +++ b/src/Renderer/Html/AbstractHtml.php @@ -44,9 +44,6 @@ abstract class AbstractHtml extends AbstractRenderer */ public const AUTO_FORMAT_CHANGES = true; - /** - * {@inheritdoc} - */ public function getResultForIdenticalsDefault(): string { return ''; @@ -105,9 +102,6 @@ public function getChanges(Differ $differ): array return $changes; } - /** - * {@inheritdoc} - */ protected function renderWorker(Differ $differ): string { $rendered = $this->redererChanges($this->getChanges($differ)); @@ -115,9 +109,6 @@ protected function renderWorker(Differ $differ): string return $this->cleanUpDummyHtmlClosures($rendered); } - /** - * {@inheritdoc} - */ protected function renderArrayWorker(array $differArray): string { $this->ensureChangesUseIntTag($differArray); @@ -199,7 +190,7 @@ final protected function formatChanges(array &$changes): void /** @phan-suppress-next-line PhanTypeInvalidLeftOperandOfBitwiseOp */ if ($block['tag'] & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) { - $block['old']['lines'] = \str_replace( + $block['old']['lines'] = str_replace( RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $block['old']['lines'] @@ -208,7 +199,7 @@ final protected function formatChanges(array &$changes): void /** @phan-suppress-next-line PhanTypeInvalidLeftOperandOfBitwiseOp */ if ($block['tag'] & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) { - $block['new']['lines'] = \str_replace( + $block['new']['lines'] = str_replace( RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $block['new']['lines'] @@ -232,10 +223,10 @@ protected function formatLines(array $lines): array * we can glue lines into a string and call functions for one time. * After that, we split the string back into lines. */ - return \explode( + return explode( RendererConstant::IMPLODE_DELIMITER, $this->formatStringFromLines( - \implode( + implode( RendererConstant::IMPLODE_DELIMITER, $lines ) @@ -288,16 +279,16 @@ protected function expandTabs(string $string, int $tabSize = 4, bool $onlyLeadin } if ($onlyLeadingTabs) { - return \preg_replace_callback( + return preg_replace_callback( "/^[ \t]{1,}/mS", // tabs and spaces may be mixed - function (array $matches) use ($tabSize): string { - return \str_replace("\t", \str_repeat(' ', $tabSize), $matches[0]); + static function (array $matches) use ($tabSize): string { + return str_replace("\t", str_repeat(' ', $tabSize), $matches[0]); }, $string ); } - return \str_replace("\t", \str_repeat(' ', $tabSize), $string); + return str_replace("\t", str_repeat(' ', $tabSize), $string); } /** @@ -309,7 +300,7 @@ function (array $matches) use ($tabSize): string { */ protected function htmlSafe(string $string): string { - return \htmlspecialchars($string, \ENT_NOQUOTES, 'UTF-8'); + return htmlspecialchars($string, \ENT_NOQUOTES, 'UTF-8'); } /** @@ -321,7 +312,7 @@ protected function htmlSafe(string $string): string */ protected function htmlFixSpaces(string $string): string { - return \str_replace(' ', ' ', $string); + return str_replace(' ', ' ', $string); } /** @@ -333,7 +324,7 @@ protected function htmlFixSpaces(string $string): string */ protected function htmlReplaceSpacesToHtmlTag(string $string): string { - return \strtr($string, [ + return strtr($string, [ ' ' => ' ', "\t" => "\t", ]); @@ -367,7 +358,7 @@ protected function ensureChangesUseIntTag(array &$changes): void */ protected function cleanUpDummyHtmlClosures(string $string): string { - return \str_replace( + return str_replace( [ RendererConstant::HTML_CLOSURES_DEL[0] . RendererConstant::HTML_CLOSURES_DEL[1], RendererConstant::HTML_CLOSURES_INS[0] . RendererConstant::HTML_CLOSURES_INS[1], diff --git a/src/Renderer/Html/Combined.php b/src/Renderer/Html/Combined.php index fae727d4..2ec05ee6 100644 --- a/src/Renderer/Html/Combined.php +++ b/src/Renderer/Html/Combined.php @@ -30,22 +30,19 @@ final class Combined extends AbstractHtml */ public const AUTO_FORMAT_CHANGES = false; - /** - * {@inheritdoc} - */ protected function redererChanges(array $changes): string { if (empty($changes)) { return $this->getResultForIdenticals(); } - $wrapperClasses = \array_merge( + $wrapperClasses = array_merge( $this->options['wrapperClasses'], ['diff', 'diff-html', 'diff-combined'] ); return - '' . + '
' . $this->renderTableHeader() . $this->renderTableHunks($changes) . '
'; @@ -292,7 +289,7 @@ protected function mergeReplaceLines(string $oldLine, string $newLine): ?string // i.e., the new line with all "..." parts removed $mergedLine = $newLine; foreach (ReverseIterator::fromArray($insParts) as $part) { - $mergedLine = \substr_replace( + $mergedLine = substr_replace( $mergedLine, '', // deletion $part['offset'], @@ -310,8 +307,8 @@ protected function mergeReplaceLines(string $oldLine, string $newLine): ?string $this->revisePartsForBoundaryNewlines($insParts, RendererConstant::HTML_CLOSURES_INS); // create a sorted merged parts array - $mergedParts = \array_merge($delParts, $insParts); - \usort($mergedParts, function (array $a, array $b): int { + $mergedParts = array_merge($delParts, $insParts); + usort($mergedParts, static function (array $a, array $b): int { // first sort by "offsetClean", "order" then by "type" return $a['offsetClean'] <=> $b['offsetClean'] ?: $a['order'] <=> $b['order'] @@ -320,7 +317,7 @@ protected function mergeReplaceLines(string $oldLine, string $newLine): ?string // insert merged parts into the cleaned line foreach (ReverseIterator::fromArray($mergedParts) as $part) { - $mergedLine = \substr_replace( + $mergedLine = substr_replace( $mergedLine, $part['content'], $part['offsetClean'], @@ -328,7 +325,7 @@ protected function mergeReplaceLines(string $oldLine, string $newLine): ?string ); } - return \str_replace("\n", '
', $mergedLine); + return str_replace("\n", '
', $mergedLine); } /** @@ -356,9 +353,9 @@ protected function analyzeClosureParts(string $line, array $closures, int $type) $partLengthSum = 0; // find the next left delimiter - while (false !== ($partStart = \strpos($line, $ld, $partEnd))) { + while (false !== ($partStart = strpos($line, $ld, $partEnd))) { // find the corresponding right delimiter - if (false === ($partEnd = \strpos($line, $rd, $partStart + $ldLength))) { + if (false === ($partEnd = strpos($line, $rd, $partStart + $ldLength))) { break; } @@ -374,7 +371,7 @@ protected function analyzeClosureParts(string $line, array $closures, int $type) // the offset in the cleaned line (i.e., the line with closure parts removed) 'offsetClean' => $partStart - $partLengthSum, // the content of the part - 'content' => \substr($line, $partStart, $partLength), + 'content' => substr($line, $partStart, $partLength), ]; $partLengthSum += $partLength; @@ -405,8 +402,8 @@ protected function markReplaceBlockDiff(array $oldBlock, array $newBlock): array $this->options ); - $mbOld->set(\implode("\n", $oldBlock)); - $mbNew->set(\implode("\n", $newBlock)); + $mbOld->set(implode("\n", $oldBlock)); + $mbNew->set(implode("\n", $newBlock)); $lineRenderer->render($mbOld, $mbNew); @@ -425,8 +422,8 @@ protected function markReplaceBlockDiff(array $oldBlock, array $newBlock): array */ protected function isLinesMergeable(string $oldLine, string $newLine, string $cleanLine): bool { - $oldLine = \str_replace(RendererConstant::HTML_CLOSURES_DEL, '', $oldLine); - $newLine = \str_replace(RendererConstant::HTML_CLOSURES_INS, '', $newLine); + $oldLine = str_replace(RendererConstant::HTML_CLOSURES_DEL, '', $oldLine); + $newLine = str_replace(RendererConstant::HTML_CLOSURES_INS, '', $newLine); $sumLength = \strlen($oldLine) + \strlen($newLine); @@ -448,16 +445,16 @@ protected function revisePartsForBoundaryNewlines(array &$parts, array $closures { [$ld, $rd] = $closures; - $ldRegex = \preg_quote($ld, '/'); - $rdRegex = \preg_quote($rd, '/'); + $ldRegex = preg_quote($ld, '/'); + $rdRegex = preg_quote($rd, '/'); for ($i = \count($parts) - 1; $i >= 0; --$i) { $part = &$parts[$i]; // deal with leading newlines - $part['content'] = \preg_replace_callback( + $part['content'] = preg_replace_callback( "/(?P{$ldRegex})(?P[\r\n]++)/u", - function (array $matches) use (&$parts, $part, $ld, $rd): string { + static function (array $matches) use (&$parts, $part, $ld, $rd): string { // add a new part for the extracted newlines $part['order'] = -1; $part['content'] = "{$ld}{$matches['nl']}{$rd}"; @@ -469,9 +466,9 @@ function (array $matches) use (&$parts, $part, $ld, $rd): string { ); // deal with trailing newlines - $part['content'] = \preg_replace_callback( + $part['content'] = preg_replace_callback( "/(?P[\r\n]++)(?P{$rdRegex})/u", - function (array $matches) use (&$parts, $part, $ld, $rd): string { + static function (array $matches) use (&$parts, $part, $ld, $rd): string { // add a new part for the extracted newlines $part['order'] = 1; $part['content'] = "{$ld}{$matches['nl']}{$rd}"; @@ -507,7 +504,7 @@ protected function customFormatLines(array $lines, int $op): array foreach ($lines as &$line) { if ($htmlClosures) { - $line = \str_replace(RendererConstant::HTML_CLOSURES, $htmlClosures, $line); + $line = str_replace(RendererConstant::HTML_CLOSURES, $htmlClosures, $line); } } diff --git a/src/Renderer/Html/Inline.php b/src/Renderer/Html/Inline.php index 72478797..330e69be 100644 --- a/src/Renderer/Html/Inline.php +++ b/src/Renderer/Html/Inline.php @@ -19,22 +19,19 @@ final class Inline extends AbstractHtml 'type' => 'Html', ]; - /** - * {@inheritdoc} - */ protected function redererChanges(array $changes): string { if (empty($changes)) { return $this->getResultForIdenticals(); } - $wrapperClasses = \array_merge( + $wrapperClasses = array_merge( $this->options['wrapperClasses'], ['diff', 'diff-html', 'diff-inline'] ); return - '' . + '
' . $this->renderTableHeader() . $this->renderTableHunks($changes) . '
'; diff --git a/src/Renderer/Html/JsonHtml.php b/src/Renderer/Html/JsonHtml.php index a7981a1c..cc7ebeaf 100644 --- a/src/Renderer/Html/JsonHtml.php +++ b/src/Renderer/Html/JsonHtml.php @@ -24,24 +24,18 @@ class JsonHtml extends AbstractHtml */ public const IS_TEXT_RENDERER = true; - /** - * {@inheritdoc} - */ public function getResultForIdenticalsDefault(): string { return '[]'; } - /** - * {@inheritdoc} - */ protected function redererChanges(array $changes): string { if ($this->options['outputTagAsString']) { $this->convertTagToString($changes); } - return \json_encode($changes, $this->options['jsonEncodeFlags']); + return json_encode($changes, $this->options['jsonEncodeFlags']); } /** @@ -58,9 +52,6 @@ protected function convertTagToString(array &$changes): void } } - /** - * {@inheritdoc} - */ protected function formatStringFromLines(string $string): string { return $this->htmlSafe($string); diff --git a/src/Renderer/Html/LineRenderer/AbstractLineRenderer.php b/src/Renderer/Html/LineRenderer/AbstractLineRenderer.php index 53209944..45454523 100644 --- a/src/Renderer/Html/LineRenderer/AbstractLineRenderer.php +++ b/src/Renderer/Html/LineRenderer/AbstractLineRenderer.php @@ -38,7 +38,8 @@ public function __construct(array $differOptions, array $rendererOptions) $this ->setDifferOptions($differOptions) - ->setRendererOptions($rendererOptions); + ->setRendererOptions($rendererOptions) + ; } /** diff --git a/src/Renderer/Html/LineRenderer/Char.php b/src/Renderer/Html/LineRenderer/Char.php index f66dabae..e13c2e8c 100644 --- a/src/Renderer/Html/LineRenderer/Char.php +++ b/src/Renderer/Html/LineRenderer/Char.php @@ -12,8 +12,6 @@ final class Char extends AbstractLineRenderer { /** - * {@inheritdoc} - * * @return static */ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface diff --git a/src/Renderer/Html/LineRenderer/Line.php b/src/Renderer/Html/LineRenderer/Line.php index 8e76c249..51387a41 100644 --- a/src/Renderer/Html/LineRenderer/Line.php +++ b/src/Renderer/Html/LineRenderer/Line.php @@ -10,8 +10,6 @@ final class Line extends AbstractLineRenderer { /** - * {@inheritdoc} - * * @return static */ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface @@ -58,7 +56,7 @@ protected function getChangedExtentRegion(MbString $mbOld, MbString $mbNew): arr // calculate $start $start = 0; - $startMax = \min($mbOld->strlen(), $mbNew->strlen()); + $startMax = min($mbOld->strlen(), $mbNew->strlen()); while ( $start < $startMax // index out of range && $mbOld->getAtRaw($start) === $mbNew->getAtRaw($start) diff --git a/src/Renderer/Html/LineRenderer/None.php b/src/Renderer/Html/LineRenderer/None.php index b8abaa5d..b48df474 100644 --- a/src/Renderer/Html/LineRenderer/None.php +++ b/src/Renderer/Html/LineRenderer/None.php @@ -9,8 +9,6 @@ final class None extends AbstractLineRenderer { /** - * {@inheritdoc} - * * @return static */ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface diff --git a/src/Renderer/Html/LineRenderer/Word.php b/src/Renderer/Html/LineRenderer/Word.php index b9e83f8f..55e7e4b4 100644 --- a/src/Renderer/Html/LineRenderer/Word.php +++ b/src/Renderer/Html/LineRenderer/Word.php @@ -13,8 +13,6 @@ final class Word extends AbstractLineRenderer { /** - * {@inheritdoc} - * * @return static */ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface @@ -39,7 +37,7 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface // thus, this should make that "wordGlues" work correctly // @see https://github.com/jfcherng/php-diff/pull/25 if ($op === SequenceMatcher::OP_DEL) { - \array_splice($newWords, $j1, 0, [$dummyHtmlClosure]); + array_splice($newWords, $j1, 0, [$dummyHtmlClosure]); } } @@ -48,27 +46,27 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface $newWords[$j2 - 1] .= RendererConstant::HTML_CLOSURES[1]; if ($op === SequenceMatcher::OP_INS) { - \array_splice($oldWords, $i1, 0, [$dummyHtmlClosure]); + array_splice($oldWords, $i1, 0, [$dummyHtmlClosure]); } } } if (!empty($hunk) && !empty($this->rendererOptions['wordGlues'])) { - $regexGlues = \array_map( - function (string $glue): string { - return \preg_quote($glue, '/'); + $regexGlues = array_map( + static function (string $glue): string { + return preg_quote($glue, '/'); }, $this->rendererOptions['wordGlues'] ); - $gluePattern = '/^(?:' . \implode('|', $regexGlues) . ')+$/uS'; + $gluePattern = '/^(?:' . implode('|', $regexGlues) . ')+$/uS'; $this->glueWordsResult($oldWords, $gluePattern); $this->glueWordsResult($newWords, $gluePattern); } - $mbOld->set(\implode('', $oldWords)); - $mbNew->set(\implode('', $newWords)); + $mbOld->set(implode('', $oldWords)); + $mbNew->set(implode('', $newWords)); return $this; } @@ -99,10 +97,10 @@ protected function glueWordsResult(array &$words, string $gluePattern): void $endClosureIdx = $idx; } } elseif (Str::startsWith($word, RendererConstant::HTML_CLOSURES[0])) { - $words[$endClosureIdx] = \substr($words[$endClosureIdx], 0, -\strlen(RendererConstant::HTML_CLOSURES[1])); - $word = \substr($word, \strlen(RendererConstant::HTML_CLOSURES[0])); + $words[$endClosureIdx] = substr($words[$endClosureIdx], 0, -\strlen(RendererConstant::HTML_CLOSURES[1])); + $word = substr($word, \strlen(RendererConstant::HTML_CLOSURES[0])); $endClosureIdx = $idx; - } elseif (!\preg_match($gluePattern, $word)) { + } elseif (!preg_match($gluePattern, $word)) { $endClosureIdx = -1; } } diff --git a/src/Renderer/Html/SideBySide.php b/src/Renderer/Html/SideBySide.php index 8f192c43..49e7cb5c 100644 --- a/src/Renderer/Html/SideBySide.php +++ b/src/Renderer/Html/SideBySide.php @@ -19,22 +19,19 @@ final class SideBySide extends AbstractHtml 'type' => 'Html', ]; - /** - * {@inheritdoc} - */ protected function redererChanges(array $changes): string { if (empty($changes)) { return $this->getResultForIdenticals(); } - $wrapperClasses = \array_merge( + $wrapperClasses = array_merge( $this->options['wrapperClasses'], ['diff', 'diff-html', 'diff-side-by-side'] ); return - '' . + '
' . $this->renderTableHeader() . $this->renderTableHunks($changes) . '
'; @@ -198,7 +195,7 @@ protected function renderTableBlockReplace(array $block): string { $ret = ''; - $lineCountMax = \max(\count($block['old']['lines']), \count($block['new']['lines'])); + $lineCountMax = max(\count($block['old']['lines']), \count($block['new']['lines'])); for ($no = 0; $no < $lineCountMax; ++$no) { if (isset($block['old']['lines'][$no])) { diff --git a/src/Renderer/Text/AbstractText.php b/src/Renderer/Text/AbstractText.php index b2f3f6c6..b1a59983 100644 --- a/src/Renderer/Text/AbstractText.php +++ b/src/Renderer/Text/AbstractText.php @@ -29,9 +29,6 @@ abstract class AbstractText extends AbstractRenderer */ protected $isCliColorEnabled = false; - /** - * {@inheritdoc} - */ public function setOptions(array $options): AbstractRenderer { parent::setOptions($options); @@ -48,17 +45,11 @@ public function setOptions(array $options): AbstractRenderer return $this; } - /** - * {@inheritdoc} - */ public function getResultForIdenticalsDefault(): string { return ''; } - /** - * {@inheritdoc} - */ protected function renderArrayWorker(array $differArray): string { throw new UnsupportedFunctionException(__METHOD__); @@ -114,31 +105,32 @@ protected function cliColoredString(string $str, ?string $symbol): string protected function hasColorSupport($stream): bool { // Follow https://no-color.org/ - if (isset($_SERVER['NO_COLOR']) || false !== \getenv('NO_COLOR')) { + if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { return false; } - if ('Hyper' === \getenv('TERM_PROGRAM')) { + if ('Hyper' === getenv('TERM_PROGRAM')) { return true; } if (\DIRECTORY_SEPARATOR === '\\') { return (\function_exists('sapi_windows_vt100_support') - && @\sapi_windows_vt100_support($stream)) - || false !== \getenv('ANSICON') - || 'ON' === \getenv('ConEmuANSI') - || 'xterm' === \getenv('TERM'); + && @sapi_windows_vt100_support($stream)) + || false !== getenv('ANSICON') + || 'ON' === getenv('ConEmuANSI') + || 'xterm' === getenv('TERM'); } if (\function_exists('stream_isatty')) { - return @\stream_isatty($stream); + return @stream_isatty($stream); } if (\function_exists('posix_isatty')) { return @posix_isatty($stream); } - $stat = @\fstat($stream); + $stat = @fstat($stream); + // Check if formatted mode is S_IFCHR return $stat ? 0020000 === ($stat['mode'] & 0170000) : false; } diff --git a/src/Renderer/Text/Context.php b/src/Renderer/Text/Context.php index ddc9b2a3..bf56ec5e 100644 --- a/src/Renderer/Text/Context.php +++ b/src/Renderer/Text/Context.php @@ -30,9 +30,6 @@ final class Context extends AbstractText SequenceMatcher::OP_INS | SequenceMatcher::OP_REP; - /** - * {@inheritdoc} - */ protected function renderWorker(Differ $differ): string { $ret = ''; @@ -151,7 +148,7 @@ protected function renderContext(string $symbol, array $context, bool $noEolAtEo return ''; } - $ret = "{$symbol} " . \implode("\n{$symbol} ", $context) . "\n"; + $ret = "{$symbol} " . implode("\n{$symbol} ", $context) . "\n"; $ret = $this->cliColoredString($ret, $symbol); if ($noEolAtEof) { diff --git a/src/Renderer/Text/JsonText.php b/src/Renderer/Text/JsonText.php index b99aa56c..6965feab 100644 --- a/src/Renderer/Text/JsonText.php +++ b/src/Renderer/Text/JsonText.php @@ -20,9 +20,6 @@ final class JsonText extends AbstractText 'type' => 'Text', ]; - /** - * {@inheritdoc} - */ protected function renderWorker(Differ $differ): string { $ret = []; @@ -35,7 +32,7 @@ protected function renderWorker(Differ $differ): string $this->convertTagToString($ret); } - return \json_encode($ret, $this->options['jsonEncodeFlags']); + return json_encode($ret, $this->options['jsonEncodeFlags']); } /** diff --git a/src/Renderer/Text/Unified.php b/src/Renderer/Text/Unified.php index e2117158..3d19e195 100644 --- a/src/Renderer/Text/Unified.php +++ b/src/Renderer/Text/Unified.php @@ -22,9 +22,6 @@ final class Unified extends AbstractText 'type' => 'Text', ]; - /** - * {@inheritdoc} - */ protected function renderWorker(Differ $differ): string { $ret = ''; @@ -135,7 +132,7 @@ protected function renderContext(string $symbol, array $context, bool $noEolAtEo return ''; } - $ret = $symbol . \implode("\n{$symbol}", $context) . "\n"; + $ret = $symbol . implode("\n{$symbol}", $context) . "\n"; $ret = $this->cliColoredString($ret, $symbol); if ($noEolAtEof) { diff --git a/src/Utility/Arr.php b/src/Utility/Arr.php index 97dccf0c..ac0d65b6 100644 --- a/src/Utility/Arr.php +++ b/src/Utility/Arr.php @@ -42,7 +42,7 @@ public static function getPartialByIndex(array $array, int $start = 0, ?int $end } // make the length non-negative - return \array_slice($array, $start, \max(0, $end - $start)); + return \array_slice($array, $start, max(0, $end - $start)); } /** diff --git a/src/Utility/Language.php b/src/Utility/Language.php index cbd415ff..b24a44b0 100644 --- a/src/Utility/Language.php +++ b/src/Utility/Language.php @@ -85,10 +85,10 @@ private static function getTranslationsByLanguage(string $language): array $fileContent = $file->fread($file->getSize()); /** @todo PHP ^7.3 JSON_THROW_ON_ERROR */ - $decoded = \json_decode($fileContent, true); + $decoded = json_decode($fileContent, true); - if (\json_last_error() !== \JSON_ERROR_NONE) { - $msg = \sprintf('Fail to decode JSON file (code %d): %s', \json_last_error(), \realpath($filePath)); + if (json_last_error() !== \JSON_ERROR_NONE) { + $msg = sprintf('Fail to decode JSON file (code %d): %s', json_last_error(), realpath($filePath)); throw new \Exception($msg); // workaround single-line throw + 120-char limit } @@ -117,10 +117,10 @@ private function resolve($target): array } // $target is a list of "key-value pairs or language ID" - return \array_reduce( + return array_reduce( $target, function ($carry, $translation) { - return \array_merge($carry, $this->resolve($translation)); + return array_merge($carry, $this->resolve($translation)); }, [] ); diff --git a/src/Utility/ReverseIterator.php b/src/Utility/ReverseIterator.php index e684ae11..7574ff31 100644 --- a/src/Utility/ReverseIterator.php +++ b/src/Utility/ReverseIterator.php @@ -27,8 +27,8 @@ public static function fromArray(array $array, int $flags = self::ITERATOR_GET_V { // iterate [key => value] pair if ($flags & self::ITERATOR_GET_BOTH) { - for (\end($array); ($key = \key($array)) !== null; \prev($array)) { - yield $key => \current($array); + for (end($array); ($key = key($array)) !== null; prev($array)) { + yield $key => current($array); } return; @@ -36,7 +36,7 @@ public static function fromArray(array $array, int $flags = self::ITERATOR_GET_V // iterate only key if ($flags & self::ITERATOR_GET_KEY) { - for (\end($array); ($key = \key($array)) !== null; \prev($array)) { + for (end($array); ($key = key($array)) !== null; prev($array)) { yield $key; } @@ -44,8 +44,8 @@ public static function fromArray(array $array, int $flags = self::ITERATOR_GET_V } // iterate only value - for (\end($array); \key($array) !== null; \prev($array)) { - yield \current($array); + for (end($array); key($array) !== null; prev($array)) { + yield current($array); } } } diff --git a/src/Utility/Str.php b/src/Utility/Str.php index c7478d4e..f3fbf3d0 100644 --- a/src/Utility/Str.php +++ b/src/Utility/Str.php @@ -14,7 +14,7 @@ final class Str */ public static function startsWith(string $haystack, string $needle): bool { - return \substr($haystack, 0, \strlen($needle)) === $needle; + return substr($haystack, 0, \strlen($needle)) === $needle; } /** @@ -25,6 +25,6 @@ public static function startsWith(string $haystack, string $needle): bool */ public static function endsWith(string $haystack, string $needle): bool { - return \substr($haystack, -\strlen($needle)) === $needle; + return substr($haystack, -\strlen($needle)) === $needle; } } diff --git a/tests/DiffHelperTest.php b/tests/DiffHelperTest.php index 64c5b8ed..e725f3b5 100644 --- a/tests/DiffHelperTest.php +++ b/tests/DiffHelperTest.php @@ -24,7 +24,7 @@ final class DiffHelperTest extends TestCase * @covers \Jfcherng\Diff\Renderer\Text\Context * @covers \Jfcherng\Diff\Renderer\Text\Unified * - * @dataProvider rendererOutputDataProvider + * @dataProvider provideRendererOutputCases * * @param string $rendererName The renderer name * @param int $idx The index @@ -33,7 +33,7 @@ final class DiffHelperTest extends TestCase public function testRendererOutput(string $rendererName, int $idx, array $testFiles): void { if (!isset($testFiles['old'], $testFiles['new'], $testFiles['result'])) { - static::markTestSkipped("Renderer output test '{$rendererName}' #{$idx} is imcomplete."); + self::markTestSkipped("Renderer output test '{$rendererName}' #{$idx} is imcomplete."); } $result = DiffHelper::calculate( @@ -44,7 +44,7 @@ public function testRendererOutput(string $rendererName, int $idx, array $testFi ['cliColorization' => RendererConstant::CLI_COLOR_DISABLE] ); - static::assertSame( + self::assertSame( $testFiles['result']->getContents(), $result, "Renderer output test '{$rendererName}' #{$idx} failed..." @@ -58,13 +58,13 @@ public function testRendererOutput(string $rendererName, int $idx, array $testFi */ public function testGetStyleSheet(): void { - static::assertIsString(DiffHelper::getStyleSheet()); + self::assertIsString(DiffHelper::getStyleSheet()); } /** * Data provider for self::testRendererOutput. */ - public function rendererOutputDataProvider(): array + public static function provideRendererOutputCases(): iterable { $rendererNames = DiffHelper::getAvailableRenderers(); @@ -93,19 +93,20 @@ public function rendererOutputDataProvider(): array */ protected function findRendererOutputTestFiles(string $rendererName): array { - $rendererNameRegex = \preg_quote($rendererName, '/'); - $fileNameRegex = "/{$rendererNameRegex}-(?P[0-9]+)-(?P[^.\-]+)\.txt$/u"; + $rendererNameRegex = preg_quote($rendererName, '/'); + $fileNameRegex = "/{$rendererNameRegex}-(?P[0-9]+)-(?P[^.\\-]+)\\.txt$/u"; $finder = (new Finder()) ->files() ->name($fileNameRegex) - ->in(__DIR__ . '/data/renderer_outputs'); + ->in(__DIR__ . '/data/renderer_outputs') + ; $ret = []; /** @var SplFileInfo $file */ foreach ($finder as $file) { - \preg_match($fileNameRegex, $file->getFilename(), $matches); + preg_match($fileNameRegex, $file->getFilename(), $matches); $idx = (int) $matches['idx']; $name = $matches['name']; diff --git a/tests/DifferTest.php b/tests/DifferTest.php index 428d47aa..96903d0b 100644 --- a/tests/DifferTest.php +++ b/tests/DifferTest.php @@ -20,7 +20,7 @@ final class DifferTest extends TestCase * * @return array the data provider */ - public function getGroupedOpcodesDataProvider(): array + public static function provideGetGroupedOpcodesCases(): iterable { return [ [ @@ -55,7 +55,7 @@ public function getGroupedOpcodesDataProvider(): array * * @covers \Jfcherng\Diff\Differ::getGroupedOpcodes * - * @dataProvider getGroupedOpcodesDataProvider + * @dataProvider provideGetGroupedOpcodesCases * * @param string $old the old * @param string $new the new @@ -63,10 +63,10 @@ public function getGroupedOpcodesDataProvider(): array */ public function testGetGroupedOpcodes(string $old, string $new, array $expected): void { - $old = \explode("\n", $old); - $new = \explode("\n", $new); + $old = explode("\n", $old); + $new = explode("\n", $new); - static::assertSame( + self::assertSame( $expected, (new Differ($old, $new))->getGroupedOpcodes() ); diff --git a/tests/IgnoreLineEndingTest.php b/tests/IgnoreLineEndingTest.php index 137fd1e6..3d37b130 100644 --- a/tests/IgnoreLineEndingTest.php +++ b/tests/IgnoreLineEndingTest.php @@ -18,20 +18,20 @@ final class IgnoreLineEndingTest extends TestCase /** * @return string[][] */ - public function provideIgnoreLineEnding(): array + public static function provideIgnoreLineEndingCases(): iterable { return [ [ - \file_get_contents(__DIR__ . '/data/ignore_line_ending/old_1.txt'), - \file_get_contents(__DIR__ . '/data/ignore_line_ending/new_1.txt'), + file_get_contents(__DIR__ . '/data/ignore_line_ending/old_1.txt'), + file_get_contents(__DIR__ . '/data/ignore_line_ending/new_1.txt'), <<<'DIFF' DIFF , true, ], [ - \file_get_contents(__DIR__ . '/data/ignore_line_ending/old_1.txt'), - \file_get_contents(__DIR__ . '/data/ignore_line_ending/new_1.txt'), + file_get_contents(__DIR__ . '/data/ignore_line_ending/old_1.txt'), + file_get_contents(__DIR__ . '/data/ignore_line_ending/new_1.txt'), <<<"DIFF" @@ -1,2 +1,2 @@ -line 1\r @@ -47,7 +47,7 @@ public function provideIgnoreLineEnding(): array } /** - * @dataProvider provideIgnoreLineEnding + * @dataProvider provideIgnoreLineEndingCases */ public function testIgnoreLineEnding( string $old, @@ -61,6 +61,6 @@ public function testIgnoreLineEnding( 'cliColorization' => RendererConstant::CLI_COLOR_DISABLE, ]); - static::assertSame($expectedDiff, $diff); + self::assertSame($expectedDiff, $diff); } } diff --git a/tests/IgnoreWhitespaceTest.php b/tests/IgnoreWhitespaceTest.php index 9515de96..649ad3e2 100644 --- a/tests/IgnoreWhitespaceTest.php +++ b/tests/IgnoreWhitespaceTest.php @@ -18,7 +18,7 @@ final class IgnoreWhitespaceTest extends TestCase /** * @return string[][] */ - public function provideIgnoreWhitespaces(): array + public static function provideIgnoreWhitespacesCases(): iterable { return [ [ @@ -113,8 +113,8 @@ function foo() DIFF ], [ - \file_get_contents(__DIR__ . '/data/ignore_whitespace/old_1.php'), - \file_get_contents(__DIR__ . '/data/ignore_whitespace/new_1.php'), + file_get_contents(__DIR__ . '/data/ignore_whitespace/old_1.php'), + file_get_contents(__DIR__ . '/data/ignore_whitespace/new_1.php'), <<<'DIFF' @@ -215,11 +215,6 @@ { @@ -135,7 +135,7 @@ function foo() } /** - * @dataProvider provideIgnoreWhitespaces + * @dataProvider provideIgnoreWhitespacesCases */ public function testIgnoreWhitespaces(string $old, string $new, string $expectedDiff): void { @@ -145,6 +145,6 @@ public function testIgnoreWhitespaces(string $old, string $new, string $expected 'cliColorization' => RendererConstant::CLI_COLOR_DISABLE, ]); - static::assertSame($expectedDiff, $diff); + self::assertSame($expectedDiff, $diff); } } diff --git a/tests/Renderer/Html/CombinedTest.php b/tests/Renderer/Html/CombinedTest.php index f76dcd10..bfe31f2c 100644 --- a/tests/Renderer/Html/CombinedTest.php +++ b/tests/Renderer/Html/CombinedTest.php @@ -24,10 +24,10 @@ final class CombinedTest extends TestCase public function testHtmlFormatting(): void { $result = DiffHelper::calculate('<', " \nA 'word']); - $result = \htmlspecialchars_decode($result); + $result = htmlspecialchars_decode($result); /** @todo PHPUnit 9, static::assertStringNotContainsString() */ - static::assertThat($result, static::logicalNot(static::stringContains(';'))); + self::assertThat($result, self::logicalNot(self::stringContains(';'))); } /** @@ -44,8 +44,8 @@ public function testHtmlEscapeForOpEq(): void ); /** @todo PHPUnit 9, static::assertStringNotContainsString() */ - static::assertThat($result, static::logicalNot(static::stringContains(''))); - static::assertThat($result, static::logicalNot(static::stringContains(''))); + self::assertThat($result, self::logicalNot(self::stringContains(''))); + self::assertThat($result, self::logicalNot(self::stringContains(''))); } /** @@ -57,15 +57,15 @@ public function testSimpleUnmergeableBlock(): void { $result = DiffHelper::calculate("111\n222\n333\n", "444\n555\n666\n", 'Combined'); - static::assertSame( + self::assertSame( [1, 1, 1, 1, 1, 1], [ - \substr_count($result, '111'), - \substr_count($result, '222'), - \substr_count($result, '333'), - \substr_count($result, '444'), - \substr_count($result, '555'), - \substr_count($result, '666'), + substr_count($result, '111'), + substr_count($result, '222'), + substr_count($result, '333'), + substr_count($result, '444'), + substr_count($result, '555'), + substr_count($result, '666'), ], "Unmerge-able block shouldn't be repeated." ); diff --git a/tests/Renderer/Html/LineRenderer/WordTest.php b/tests/Renderer/Html/LineRenderer/WordTest.php index 685d0889..81a2b9f4 100644 --- a/tests/Renderer/Html/LineRenderer/WordTest.php +++ b/tests/Renderer/Html/LineRenderer/WordTest.php @@ -31,11 +31,11 @@ public function testRenderWordGlues1(): void $word->render($mbOld, $mbNew); - $oldDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get()); - $newDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get()); + $oldDiff = str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get()); + $newDiff = str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get()); - static::assertSame('good-looking-x', $oldDiff); - static::assertSame('good--y', $newDiff); + self::assertSame('good-looking-x', $oldDiff); + self::assertSame('good--y', $newDiff); } /** @@ -53,10 +53,10 @@ public function testRenderWordGlues2(): void $word->render($mbOld, $mbNew); - $oldDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get()); - $newDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get()); + $oldDiff = str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get()); + $newDiff = str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get()); - static::assertSame('of the Indo-Euopearn legguanas, Porto-Idno-Eorpuaen, did not have aieltrcs. Msot of the lanaguges in this flamiy do not hvae diiefnte or ieiinfntde atrciels: three is no actirle in Ltain or Ssknarit, nor in some meodrn Indo-Eoeapurn lgagaenus, scuh as the falmeiis of Salvic lnggaeuas (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $oldDiff); - static::assertSame('of the Indo-European languages, Proto-Indo-European, did not have articles. Most of the languages in this family do not have definite or indefinite articles: there is no article in Latin or Sanskrit, nor in some modern Indo-European languages, such as the families of Slavic languages (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $newDiff); + self::assertSame('of the Indo-Euopearn legguanas, Porto-Idno-Eorpuaen, did not have aieltrcs. Msot of the lanaguges in this flamiy do not hvae diiefnte or ieiinfntde atrciels: three is no actirle in Ltain or Ssknarit, nor in some meodrn Indo-Eoeapurn lgagaenus, scuh as the falmeiis of Salvic lnggaeuas (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $oldDiff); + self::assertSame('of the Indo-European languages, Proto-Indo-European, did not have articles. Most of the languages in this family do not have definite or indefinite articles: there is no article in Latin or Sanskrit, nor in some modern Indo-European languages, such as the families of Slavic languages (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $newDiff); } } diff --git a/tests/Renderer/RendererTest.php b/tests/Renderer/RendererTest.php index e6f4dd6b..ea019134 100644 --- a/tests/Renderer/RendererTest.php +++ b/tests/Renderer/RendererTest.php @@ -40,7 +40,7 @@ public function testSetOptionsWithLanguageArray(): void ['language' => $languageArrayTest] ); - static::assertStringContainsString( + self::assertStringContainsString( $testMarker, $diffResult, 'Rederer options: "language" array should work.' @@ -94,7 +94,7 @@ public function testSetOptionsWithResultForIdenticals(): void ['resultForIdenticals' => $testMarker] ); - static::assertSame( + self::assertSame( $testMarker, $diffResult, 'Rederer options: result for identicals should work.' @@ -153,9 +153,9 @@ public function testHtmlRendererRenderWithResultFromJsonRenderer(): void ['outputTagAsString' => false] + $rendererOptions ); - static::assertSame( + self::assertSame( $goldenResult, - $renderer->renderArray(\json_decode($jsonResult, true)), + $renderer->renderArray(json_decode($jsonResult, true)), "HTML renderers should be able to render with JSON result. ('outputTagAsString' => false)" ); @@ -168,9 +168,9 @@ public function testHtmlRendererRenderWithResultFromJsonRenderer(): void ['outputTagAsString' => true] + $rendererOptions ); - static::assertSame( + self::assertSame( $goldenResult, - $renderer->renderArray(\json_decode($jsonResult, true)), + $renderer->renderArray(json_decode($jsonResult, true)), "HTML renderers should be able to render with JSON result. ('outputTagAsString' => true)" ); } @@ -188,6 +188,6 @@ public function testTextRendererRenderWithResultFromJsonRenderer(): void $jsonResult = DiffHelper::calculate('_TEST_MARKER_OLD_', '_TEST_MARKER_NEW_', 'JsonHtml'); $textRenderer = RendererFactory::make('Unified'); - $UnifiedResult = $textRenderer->renderArray(\json_decode($jsonResult, true)); + $UnifiedResult = $textRenderer->renderArray(json_decode($jsonResult, true)); } } diff --git a/tests/Utility/LanguageTest.php b/tests/Utility/LanguageTest.php index 61248c4f..8132c3b1 100644 --- a/tests/Utility/LanguageTest.php +++ b/tests/Utility/LanguageTest.php @@ -17,7 +17,7 @@ final class LanguageTest extends TestCase /** * The Language object. * - * @var \Jfcherng\Diff\Utility\Language + * @var Language */ protected $languageObj; @@ -37,10 +37,10 @@ protected function setUp(): void public function testLoad(): void { $this->languageObj->load('eng'); - static::assertArrayHasKey('differences', $this->languageObj->getTranslations()); + self::assertArrayHasKey('differences', $this->languageObj->getTranslations()); $this->languageObj->load(['hahaha' => '哈哈哈']); - static::assertArrayHasKey('hahaha', $this->languageObj->getTranslations()); + self::assertArrayHasKey('hahaha', $this->languageObj->getTranslations()); $this->languageObj->load([ 'eng', @@ -48,9 +48,9 @@ public function testLoad(): void ['hahaha_1' => '哈哈哈_999'], ]); $translations = $this->languageObj->getTranslations(); - static::assertSame('Differences', $translations['differences']); - static::assertSame('哈哈哈_999', $translations['hahaha_1']); - static::assertSame('哈哈哈_2', $translations['hahaha_2']); + self::assertSame('Differences', $translations['differences']); + self::assertSame('哈哈哈_999', $translations['hahaha_1']); + self::assertSame('哈哈哈_2', $translations['hahaha_2']); $this->expectException(\InvalidArgumentException::class); $this->languageObj->load(5); @@ -63,12 +63,12 @@ public function testLoad(): void */ public function testTranslate(): void { - static::assertSame( + self::assertSame( 'Differences', $this->languageObj->translate('differences') ); - static::assertStringMatchesFormat( + self::assertStringMatchesFormat( '![%s]', $this->languageObj->translate('a_non_existing_key') ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ab5cc496..2d96fff7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -\error_reporting(\E_ALL); -\ini_set('display_errors', '1'); +error_reporting(\E_ALL); +ini_set('display_errors', '1'); include __DIR__ . '/../vendor/autoload.php';