Define a constant instead of duplicating this literal "charBCodePoint" 4 times. Open
$parts = \array_combine(['charACodePoint', 'charBCodePoint', 'comment'], $parts);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "charA" 7 times. Open
$isCharAAscii = \strlen($row['charA']) === 1 && \ord($row['charA']) < 0x80;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "charACodePoint" 7 times. Open
'codePoint' => $row['charACodePoint'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "charB" 4 times. Open
$isCharBAscii = \strlen($row['charB']) === 1 && \ord($row['charB']) < 0x80;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "charADesc" 3 times. Open
'desc' => $row['charADesc'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Unexpected tabs found. Open
/**
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
$key = $row['charA'];
- Exclude checks
Unexpected tabs found. Open
);
- Exclude checks
Unexpected tabs found. Open
$php = \preg_replace_callback('/^(\s*)/m', static function ($matches) {
- Exclude checks
Unexpected tabs found. Open
// only interested in chars that are confusable with an ascii char
- Exclude checks
Unexpected tabs found. Open
return \strcmp($rowA['charA'], $rowB['charA']);
- Exclude checks
Unexpected tabs found. Open
return $isEmptyOrComment === false;
- Exclude checks
Unexpected tabs found. Open
});
- Exclude checks
Unexpected tabs found. Open
// remove leading 00 pairs
- Exclude checks
Unexpected tabs found. Open
}, \explode(' ', $parts['charACodePoint']))),
- Exclude checks
Unexpected tabs found. Open
'charADesc' => $parts['charADesc'],
- Exclude checks
Unexpected tabs found. Open
$isCharAAscii = \strlen($row['charA']) === 1 && \ord($row['charA']) < 0x80;
- Exclude checks
Unexpected tabs found. Open
unset($row['charA']);
- Exclude checks
Unexpected tabs found. Open
{
- Exclude checks
Unexpected tabs found. Open
'charA' => \implode('', \array_map(static function ($hex) {
- Exclude checks
Unexpected tabs found. Open
protected static function varExportPretty($val)
- Exclude checks
Unexpected tabs found. Open
$php = \var_export($val, true);
- Exclude checks
Unexpected tabs found. Open
$isCharBAscii = \strlen($row['charB']) === 1 && \ord($row['charB']) < 0x80;
- Exclude checks
Unexpected tabs found. Open
foreach ($rows as $row) {
- Exclude checks
Unexpected tabs found. Open
return $rowsNew;
- Exclude checks
Unexpected tabs found. Open
$parts['charBCodePoint'] = \implode(' ', \array_map(static function ($codePoint) {
- Exclude checks
Unexpected tabs found. Open
// remove leading 00 pairs
- Exclude checks
Unexpected tabs found. Open
'charACodePoint' => $parts['charACodePoint'],
- Exclude checks
Unexpected tabs found. Open
public static $filepathSrc = 'https://www.unicode.org/Public/security/latest/confusables.txt';
- Exclude checks
Unexpected tabs found. Open
\file_put_contents($filepathOut, $php);
- Exclude checks
Unexpected tabs found. Open
\usort($rows, static function ($rowA, $rowB) {
- Exclude checks
Unexpected tabs found. Open
'desc' => $row['charADesc'],
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
$parts = \array_map('trim', $parts);
- Exclude checks
Unexpected tabs found. Open
}, \explode(' ', $parts['charBCodePoint'])));
- Exclude checks
Unexpected tabs found. Open
return \mb_chr($codePoint, 'UTF-8');
- Exclude checks
Unexpected tabs found. Open
}, \explode(' ', $parts['charBCodePoint']))),
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
}, $php);
- Exclude checks
Unexpected tabs found. Open
private static function getParsedRows()
- Exclude checks
Unexpected tabs found. Open
$parts = \array_merge($parts, $matches);
- Exclude checks
Unexpected tabs found. Open
$php = \preg_replace('/=> \n\s+array/', '=> array', $php);
- Exclude checks
Unexpected tabs found. Open
/** @var string */
- Exclude checks
Unexpected tabs found. Open
{
- Exclude checks
Unexpected tabs found. Open
});
- Exclude checks
Unexpected tabs found. Open
protected static function parseRow($row)
- Exclude checks
Unexpected tabs found. Open
$parts = \array_combine(['charACodePoint', 'charBCodePoint', 'comment'], $parts);
- Exclude checks
Unexpected tabs found. Open
protected $charData = array();
- Exclude checks
Unexpected tabs found. Open
{
- Exclude checks
Unexpected tabs found. Open
return $isCharAAscii === false && $isCharBAscii;
- Exclude checks
Unexpected tabs found. Open
// rekey
- Exclude checks
Unexpected tabs found. Open
/**
- Exclude checks
Unexpected tabs found. Open
$parts = \explode('; ', $row, 3);
- Exclude checks
Unexpected tabs found. Open
return \preg_replace('/^(00)+/', '', $codePoint);
- Exclude checks
Unexpected tabs found. Open
public static function update()
- Exclude checks
Unexpected tabs found. Open
. 'return ' . self::varExportPretty(self::build()) . ";\n";
- Exclude checks
Unexpected tabs found. Open
/**
- Exclude checks
Unexpected tabs found. Open
$rows = \array_filter($rows, static function ($row) {
- Exclude checks
Unexpected tabs found. Open
});
- Exclude checks
Unexpected tabs found. Open
\ksort($rowsNew);
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
return \mb_chr($codePoint, 'UTF-8');
- Exclude checks
Unexpected tabs found. Open
'charB' => \implode('', \array_map(static function ($hex) {
- Exclude checks
Unexpected tabs found. Open
$php = \str_replace('array (', 'array(', $php);
- Exclude checks
Unexpected tabs found. Open
return \str_repeat($matches[1], 2);
- Exclude checks
Unexpected tabs found. Open
$filepathOut = __DIR__ . '/../src/Debug/Dump/charData.php';
- Exclude checks
Unexpected tabs found. Open
$rows = \file(self::$filepathSrc);
- Exclude checks
Unexpected tabs found. Open
}, $rows);
- Exclude checks
Unexpected tabs found. Open
/**
- Exclude checks
Unexpected tabs found. Open
'isXid' => empty($parts['notXid']),
- Exclude checks
Unexpected tabs found. Open
$php = '<?php // phpcs:ignore SlevomatCodingStandard.Files.FileLength' . "\n\n"
- Exclude checks
Unexpected tabs found. Open
public static function build()
- Exclude checks
Unexpected tabs found. Open
// not interested in ascii chars that are confusable with other ascii chars
- Exclude checks
Unexpected tabs found. Open
if (isset($rowsNew[$key])) {
- Exclude checks
Unexpected tabs found. Open
$isEmptyOrComment = \strlen(\trim($row)) === 0 || $row[0] === '#';
- Exclude checks
Unexpected tabs found. Open
return \array_map(static function ($row) {
- Exclude checks
Unexpected tabs found. Open
\preg_match('/^(?P<category>\w+)\t#(?P<notXid>\*?)\s*(?P<example>\(.*?\))\s*(?P<charADesc>.*?) → (?P<charBDesc>.*?)(\s+#.*)?$/u', $parts['comment'], $matches);
- Exclude checks
Unexpected tabs found. Open
$rows = self::getParsedRows();
- Exclude checks
Unexpected tabs found. Open
$rows = \array_filter($rows, static function ($row) {
- Exclude checks
Unexpected tabs found. Open
{
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
'codePoint' => $row['charACodePoint'],
- Exclude checks
Unexpected tabs found. Open
{
- Exclude checks
Unexpected tabs found. Open
$codePoint = \hexdec($hex);
- Exclude checks
Unexpected tabs found. Open
$codePoint = \hexdec($hex);
- Exclude checks
Unexpected tabs found. Open
return \preg_replace('/^(00)+/', '', $codePoint);
- Exclude checks
Unexpected tabs found. Open
return array(
- Exclude checks
Unexpected tabs found. Open
return $php;
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
$rowsNew = require __DIR__ . '/charData.php';
- Exclude checks
Unexpected tabs found. Open
continue;
- Exclude checks
Unexpected tabs found. Open
$rowsNew[$key] = array(
- Exclude checks
Unexpected tabs found. Open
);
- Exclude checks
Unexpected tabs found. Open
}
- Exclude checks
Unexpected tabs found. Open
return self::parseRow($row);
- Exclude checks
Unexpected tabs found. Open
}, \explode(' ', $parts['charACodePoint'])));
- Exclude checks
Unexpected tabs found. Open
/**
- Exclude checks
Unexpected tabs found. Open
'similarTo' => $row['charB'],
- Exclude checks
Unexpected tabs found. Open
$parts['charACodePoint'] = \implode(' ', \array_map(static function ($codePoint) {
- Exclude checks
Unexpected tabs found. Open
$php = \str_replace('\'\' . "\0" . \'\'', '"\x00"', $php);
- Exclude checks