Missing class import via use statement (line '63', column '14'). Open
throw new \App\Exceptions\FieldException('LBL_INVALID_COUNTRY_CODE');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '81', column '13'). Open
throw new \App\Exceptions\FieldException('LBL_INVALID_PHONE_NUMBER');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\App\Log' in method 'getDetails'. Open
\App\Log::info($e->getMessage(), __CLASS__);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\libphonenumber\PhoneNumberUtil' in method 'verifyNumber'. Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\libphonenumber\PhoneNumberUtil' in method 'getDetails'. Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'getDetails'. Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'getDetails'. Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'verifyNumber'. Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Log' in method 'verifyNumber'. Open
\App\Log::info($e->getMessage(), __CLASS__);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'verifyNumber'. Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "country" 3 times. Open
'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
- 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.
Catching undeclared class \libphonenumber\NumberParseException
Open
} catch (\libphonenumber\NumberParseException $e) {
- Exclude checks
Reference to constant INTERNATIONAL
from undeclared class \libphonenumber\PhoneNumberFormat
Open
'number' => $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL),
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\geocoding\PhoneNumberOfflineGeocoder
Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\PhoneNumberToCarrierMapper
Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Call to method getMessage
from undeclared class \libphonenumber\NumberParseException
Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Call to method info
from undeclared class \App\Log
Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\PhoneNumberToCarrierMapper
Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\geocoding\PhoneNumberOfflineGeocoder
Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Call to method info
from undeclared class \App\Log
Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Call to method getMessage
from undeclared class \libphonenumber\NumberParseException
Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Reference to constant INTERNATIONAL
from undeclared class \libphonenumber\PhoneNumberFormat
Open
$phoneNumber = $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\PhoneNumberUtil
Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Exclude checks
Call to method getInstance
from undeclared class \libphonenumber\PhoneNumberUtil
Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Exclude checks
Catching undeclared class \libphonenumber\NumberParseException
Open
} catch (\libphonenumber\NumberParseException $e) {
- Exclude checks
Returning type array{isValidNumber:true,number:mixed,geocoding:mixed,carrier:mixed,country:mixed}
but verifyNumber()
is declared to return bool
Open
'isValidNumber' => true,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \App\Exceptions\FieldException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Line exceeds 120 characters; contains 177 characters Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'isValidNumber' => true,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Verify phone number.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($phoneUtil->isValidNumber($swissNumberProto)) {
- Exclude checks
Line exceeds 120 characters; contains 172 characters Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get phone details.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'number' => $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\libphonenumber\NumberParseException $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$phoneNumber = $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\FieldException('LBL_INVALID_COUNTRY_CODE');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $phoneNumber
- Exclude checks
Line exceeds 120 characters; contains 177 characters Open
'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'number' => $phoneNumber,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$swissNumberProto = $phoneUtil->parse($phoneNumber, $phoneCountry);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $phoneCountry
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getDetails(string $phoneNumber, ?string $phoneCountry = null)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $phoneCountry
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function verifyNumber($phoneNumber, $phoneCountry)
- Exclude checks
Line exceeds 120 characters; contains 172 characters Open
'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $phoneNumber
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($phoneCountry && !\in_array($phoneCountry, $phoneUtil->getSupportedRegions())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$swissNumberProto = $phoneUtil->parse($phoneNumber, $phoneCountry);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array|bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($phoneUtil->isValidNumber($swissNumberProto)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::info($e->getMessage(), __CLASS__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\FieldException('LBL_INVALID_PHONE_NUMBER');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\libphonenumber\NumberParseException $e) {
- Exclude checks