Skip to content

Commit

Permalink
🎨 CS Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
giggsey committed Apr 29, 2024
1 parent 20ffd64 commit 7e31d93
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 161 deletions.
7 changes: 7 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
'@PSR12' => true,
'@PHP81Migration' => true,
'single_quote' => true,
'no_unused_imports' => true,
'no_superfluous_phpdoc_tags' => [
'allow_hidden_params' => true,
'allow_mixed' => true,
'remove_inheritdoc' => true,
],
'phpdoc_trim' => true,
]
)->setFinder($finder);
65 changes: 14 additions & 51 deletions build/BuildMetadataFromXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ public static function validateRE(string $regex, bool $removeWhitespace = false)
}

/**
*
* @param DOMElement|string $inputXmlFile
* @param boolean $liteBuild
* @param boolean $specialBuild
* @param bool $isShortNumberMetadata
* @param bool $isAlternateFormatsMetadata
* @return PhoneMetadata[]
*/
public static function buildPhoneMetadataCollection(
Expand Down Expand Up @@ -127,11 +123,6 @@ public static function buildPhoneMetadataCollection(
}

/**
* @param string $regionCode
* @param DOMElement $element
* @param bool $isShortNumberMetadata
* @param bool $isAlternateFormatsMetadata
* @return PhoneMetadata
*/
public static function loadCountryMetadata(string $regionCode, DOMElement $element, bool $isShortNumberMetadata, bool $isAlternateFormatsMetadata): PhoneMetadata
{
Expand All @@ -150,11 +141,8 @@ public static function loadCountryMetadata(string $regionCode, DOMElement $eleme
/**
* Processes the custom build flags and gets a MetadataFilter which may be used to
* filter PhoneMetadata objects. Incompatible flag combinations throw RuntimeException.
* @param bool $liteBuild
* @param bool $specialBuild
* @return MetadataFilter
*/
public static function getMetadataFilter($liteBuild, $specialBuild): MetadataFilter
public static function getMetadataFilter(bool $liteBuild, bool $specialBuild): MetadataFilter
{
if ($specialBuild) {
if ($liteBuild) {
Expand All @@ -172,42 +160,27 @@ public static function getMetadataFilter($liteBuild, $specialBuild): MetadataFil
/**
* Returns the national prefix of the provided country element.
* @internal
* @return string
*/
public static function getNationalPrefix(DOMElement $element): string
{
return $element->hasAttribute(self::NATIONAL_PREFIX) ? $element->getAttribute(self::NATIONAL_PREFIX) : '';
}

/**
*
* @internal
* @param string $nationalPrefix
* @return string
*/
public static function getNationalPrefixFormattingRuleFromElement(DOMElement $element, $nationalPrefix): string
public static function getNationalPrefixFormattingRuleFromElement(DOMElement $element, string $nationalPrefix): string
{
$nationalPrefixFormattingRule = $element->getAttribute(self::NATIONAL_PREFIX_FORMATTING_RULE);
// Replace $NP with national prefix and $FG with the first group ($1).
$nationalPrefixFormattingRule = \str_replace(
return \str_replace(
['$NP', '$FG'],
[$nationalPrefix, '$1'],
$nationalPrefixFormattingRule
);
return $nationalPrefixFormattingRule;
}

/**
*
* @internal
* @param string $regionCode
* @param string $nationalPrefix
* @return PhoneMetadata
*/
public static function loadTerritoryTagMetadata(
$regionCode,
string $regionCode,
DOMElement $element,
$nationalPrefix
string $nationalPrefix
): PhoneMetadata {
$metadata = new PhoneMetadata();
$metadata->setId($regionCode);
Expand All @@ -228,7 +201,7 @@ public static function loadTerritoryTagMetadata(
$metadata->setNationalPrefixTransformRule(self::validateRE($element->getAttribute(self::NATIONAL_PREFIX_TRANSFORM_RULE)));
}
}
if ($nationalPrefix != '') {
if ($nationalPrefix !== '') {
$metadata->setNationalPrefix($nationalPrefix);
if (!$metadata->hasNationalPrefixForParsing()) {
$metadata->setNationalPrefixForParsing($nationalPrefix);
Expand All @@ -252,16 +225,13 @@ public static function loadTerritoryTagMetadata(
* nationalPrefixOptionalWhenFormatting. The nationalPrefix, nationalPrefixFormattingRule and
* nationalPrefixOptionalWhenFormatting values are provided from the parent (territory) element.
* @internal
* @param string $nationalPrefix
* @param string $nationalPrefixFormattingRule
* @param bool $nationalPrefixOptionalWhenFormatting
*/
public static function loadAvailableFormats(
PhoneMetadata $metadata,
DOMElement $element,
$nationalPrefix,
$nationalPrefixFormattingRule,
$nationalPrefixOptionalWhenFormatting
string $nationalPrefix,
string $nationalPrefixFormattingRule,
bool $nationalPrefixOptionalWhenFormatting
): void {
$carrierCodeFormattingRule = '';
if ($element->hasAttribute(self::CARRIER_CODE_FORMATTING_RULE)) {
Expand All @@ -285,7 +255,7 @@ public static function loadAvailableFormats(
$format->setNationalPrefixFormattingRule($nationalPrefixFormattingRule);
}
if ($numberFormatElement->hasAttribute(self::NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING)) {
$format->setNationalPrefixOptionalWhenFormatting($numberFormatElement->getAttribute(self::NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING) === 'true' ? true : false);
$format->setNationalPrefixOptionalWhenFormatting($numberFormatElement->getAttribute(self::NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING) === 'true');
} else {
$format->setNationalPrefixOptionalWhenFormatting($nationalPrefixOptionalWhenFormatting);
}
Expand Down Expand Up @@ -314,20 +284,16 @@ public static function loadAvailableFormats(
}

/**
* @internal
* @param string $nationalPrefix
* @return string
*/
public static function getDomesticCarrierCodeFormattingRuleFromElement(DOMElement $element, $nationalPrefix): string
public static function getDomesticCarrierCodeFormattingRuleFromElement(DOMElement $element, string $nationalPrefix): string
{
$carrierCodeFormattingRule = $element->getAttribute(self::CARRIER_CODE_FORMATTING_RULE);
// Replace $FG with the first group ($1) and $NP with the national prefix.
$carrierCodeFormattingRule = \str_replace(
return \str_replace(
['$NP', '$FG'],
[$nationalPrefix, '$1'],
$carrierCodeFormattingRule
);
return $carrierCodeFormattingRule;
}

/**
Expand All @@ -345,8 +311,8 @@ public static function loadNationalFormat(
$format->setPattern(self::validateRE($numberFormatElement->getAttribute(self::PATTERN)));

$formatPattern = $numberFormatElement->getElementsByTagName(self::FORMAT);
if ($formatPattern->length != 1) {
$countryId = $metadata->getId() != '' ? $metadata->getId() : $metadata->getCountryCode();
if ($formatPattern->length !== 1) {
$countryId = $metadata->getId() !== '' ? $metadata->getId() : $metadata->getCountryCode();
throw new \RuntimeException('Invalid number of format patterns for country: ' . $countryId);
}
$nationalFormat = $formatPattern->item(0)->firstChild->nodeValue;
Expand Down Expand Up @@ -410,7 +376,6 @@ public static function loadInternationalFormat(

/**
* @internal
* @param bool $isShortNumberMetadata
*/
public static function setRelevantDescPatterns(PhoneMetadata $metadata, DOMElement $element, bool $isShortNumberMetadata): void
{
Expand Down Expand Up @@ -744,8 +709,6 @@ public static function processPhoneNumberDescElement(

/**
* @param int[] $possibleLengths
* @param PhoneNumberDesc $desc
* @return bool
*/
private static function arePossibleLengthsEqual(array $possibleLengths, PhoneNumberDesc $desc): bool
{
Expand Down
4 changes: 0 additions & 4 deletions build/BuildMetadataPHPFromXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function start(string $inputFile, string $outputDir, string $filePrefix,

/**
* @param PhoneMetadata[] $metadataCollection
* @param string $filePrefix
*/
private function writeMetadataToFile(array $metadataCollection, string $filePrefix): void
{
Expand All @@ -70,9 +69,6 @@ private function writeMetadataToFile(array $metadataCollection, string $filePref

/**
* @param array<int,array<string>> $countryCodeToRegionCodeMap
* @param string $outputDir
* @param string $mappingClass
* @return void
*/
private function writeCountryCallingCodeMappingToFile(array $countryCodeToRegionCodeMap, string $outputDir, string $mappingClass): void
{
Expand Down
3 changes: 1 addition & 2 deletions build/Commands/BuildMetadataPHPFromXMLCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace libphonenumber\buildtools\Commands;

use libphonenumber\buildtools\BuildMetadataPHPFromXml;
use PHPStan\Parallel\Process;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -36,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$input->getArgument('DataPrefix'),
$input->getArgument('MappingClass'),
$input->getArgument('MappingClassLocation'),
($input->getArgument('LiteBuild') === 'true') ? true : false
$input->getArgument('LiteBuild') === 'true'
);

return self::SUCCESS;
Expand Down
5 changes: 0 additions & 5 deletions build/MetadataFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public static function forLiteBuild(): static
* duplicates, malformed strings, or strings where field tokens do not correspond to strings in
* the sets of excludable fields. We also throw RuntimeException for empty strings since such
* strings should be treated as a special case by the flag checking code and not passed here.
* @param string $string
* @return array<string,string[]>
*/
public static function parseFieldMapFromString(string $string): array
Expand Down Expand Up @@ -319,7 +318,6 @@ public function filterMetadata(PhoneMetadata $metadata): void

/**
* @param string $type
* @return PhoneNumberDesc
*/
private function getFiltered($type, PhoneNumberDesc $desc): PhoneNumberDesc
{
Expand All @@ -346,9 +344,6 @@ private function getFiltered($type, PhoneNumberDesc $desc): PhoneNumberDesc
}

/**
* @param $parent
* @param $child
* @return bool
*/
public function shouldDrop(string $parent, ?string $child = null): bool
{
Expand Down
5 changes: 0 additions & 5 deletions src/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Matcher
private int $searchIndex = 0;

/**
* @param string $pattern
* @param string $subject
*/
public function __construct(string $pattern, string $subject)
{
Expand All @@ -36,9 +34,6 @@ public function __construct(string $pattern, string $subject)
}

/**
* @param string $type
* @param int $offset
* @return bool
*/
protected function doMatch(string $type = 'find', int $offset = 0): bool
{
Expand Down
8 changes: 2 additions & 6 deletions src/MultiFileMetadataSourceImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(protected MetadataLoaderInterface $metadataLoader, ?
}

/**
* @inheritdoc
*
*/
public function getMetadataForRegion(string $regionCode): PhoneMetadata
{
Expand All @@ -56,7 +56,7 @@ public function getMetadataForRegion(string $regionCode): PhoneMetadata
}

/**
* @inheritdoc
*
*/
public function getMetadataForNonGeographicalRegion(int $countryCallingCode): PhoneMetadata
{
Expand All @@ -68,10 +68,6 @@ public function getMetadataForNonGeographicalRegion(int $countryCallingCode): Ph
}

/**
* @param string $filePrefix
* @param string $regionCode
* @param int $countryCallingCode
* @param MetadataLoaderInterface $metadataLoader
*/
public function loadMetadataFromFile(string $filePrefix, string $regionCode, int $countryCallingCode, MetadataLoaderInterface $metadataLoader): void
{
Expand Down
1 change: 0 additions & 1 deletion src/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function __construct()
}

/**
* @return NumberFormat
*/
public function clear(): NumberFormat
{
Expand Down
2 changes: 0 additions & 2 deletions src/PhoneMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public function numberFormatSize(): int
}

/**
* @param int $index
* @return NumberFormat
*/
public function getNumberFormat(int $index): NumberFormat
{
Expand Down
8 changes: 2 additions & 6 deletions src/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class PhoneNumber implements \Serializable, \Stringable
/**
* The country calling code for this number, as defined by the International Telecommunication Union
* (ITU). For example, this would be 1 for NANPA countries, and 33 for France.
*/
protected ?int $countryCode = null;
/**
Expand Down Expand Up @@ -322,8 +321,6 @@ public function setExtension(string $value): PhoneNumber

/**
* Returns whether this phone number has the italian leading zero information set.
*
* @return bool
*/
public function hasItalianLeadingZero(): bool
{
Expand Down Expand Up @@ -506,7 +503,6 @@ public function equals(PhoneNumber $other): bool

/**
* Returns a string representation of this phone number.
* @return string
*/
public function __toString(): string
{
Expand All @@ -531,7 +527,7 @@ public function __toString(): string
}

/**
* @inheritDoc
*
*/
public function serialize(): ?string
{
Expand All @@ -556,7 +552,7 @@ public function __serialize(): array
}

/**
* @inheritDoc
*
*/
public function unserialize($data)
{
Expand Down
4 changes: 0 additions & 4 deletions src/PhoneNumberMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct(int $start, string $rawString, private PhoneNumber $

/**
* Returns the phone number matched by the receiver.
* @return PhoneNumber
*/
public function number(): PhoneNumber
{
Expand All @@ -44,7 +43,6 @@ public function number(): PhoneNumber

/**
* Returns the start index of the matched phone number within the searched text.
* @return int
*/
public function start(): int
{
Expand All @@ -53,7 +51,6 @@ public function start(): int

/**
* Returns the exclusive end index of the matched phone number within the searched text.
* @return int
*/
public function end(): int
{
Expand All @@ -62,7 +59,6 @@ public function end(): int

/**
* Returns the raw string matched as a phone number in the searched text.
* @return string
*/
public function rawString(): string
{
Expand Down
Loading

0 comments on commit 7e31d93

Please sign in to comment.