YetiForceCompany/YetiForceCRM

View on GitHub
app/Fields/Phone.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '63', column '14').
Open

            throw new \App\Exceptions\FieldException('LBL_INVALID_COUNTRY_CODE');
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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');
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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__);
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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();
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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();
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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()),
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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()),
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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()),
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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__);
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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()),
Severity: Minor
Found in app/Fields/Phone.php by phpmd

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),
Severity: Critical
Found in app/Fields/Phone.php by sonar-php

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) {
Severity: Critical
Found in app/Fields/Phone.php by phan

Reference to constant INTERNATIONAL from undeclared class \libphonenumber\PhoneNumberFormat
Open

                    'number' => $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL),
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\geocoding\PhoneNumberOfflineGeocoder
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\PhoneNumberToCarrierMapper
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getMessage from undeclared class \libphonenumber\NumberParseException
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method info from undeclared class \App\Log
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\PhoneNumberToCarrierMapper
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\geocoding\PhoneNumberOfflineGeocoder
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method info from undeclared class \App\Log
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getMessage from undeclared class \libphonenumber\NumberParseException
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Critical
Found in app/Fields/Phone.php by phan

Reference to constant INTERNATIONAL from undeclared class \libphonenumber\PhoneNumberFormat
Open

                $phoneNumber = $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\PhoneNumberUtil
Open

        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
Severity: Critical
Found in app/Fields/Phone.php by phan

Call to method getInstance from undeclared class \libphonenumber\PhoneNumberUtil
Open

        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
Severity: Critical
Found in app/Fields/Phone.php by phan

Catching undeclared class \libphonenumber\NumberParseException
Open

        } catch (\libphonenumber\NumberParseException $e) {
Severity: Critical
Found in app/Fields/Phone.php by phan

Returning type array{isValidNumber:true,number:mixed,geocoding:mixed,carrier:mixed,country:mixed} but verifyNumber() is declared to return bool
Open

                    'isValidNumber' => true,
Severity: Minor
Found in app/Fields/Phone.php by phan

Spaces must be used to indent lines; tabs are not allowed
Open

        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \App\Exceptions\FieldException
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        try {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Line exceeds 120 characters; contains 177 characters
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                return [
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'isValidNumber' => true,
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Verify phone number.
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            if ($phoneUtil->isValidNumber($swissNumberProto)) {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Line exceeds 120 characters; contains 172 characters
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get phone details.
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'number' => $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            return [
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                return [
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        } catch (\libphonenumber\NumberParseException $e) {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                $phoneNumber = $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new \App\Exceptions\FieldException('LBL_INVALID_COUNTRY_CODE');
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string      $phoneNumber
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Line exceeds 120 characters; contains 177 characters
Open

                    'geocoding' => \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance()->getDescriptionForNumber($swissNumberProto, \App\Language::getLanguage()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return false;
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'number' => $phoneNumber,
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        try {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $swissNumberProto = $phoneUtil->parse($phoneNumber, $phoneCountry);
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string|null $phoneCountry
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function getDetails(string $phoneNumber, ?string $phoneCountry = null)
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            ];
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return bool
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string|null $phoneCountry
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                    'country' => $phoneUtil->getRegionCodeForNumber($swissNumberProto),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function verifyNumber($phoneNumber, $phoneCountry)
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Line exceeds 120 characters; contains 172 characters
Open

                    'carrier' => \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForValidNumber($swissNumberProto, \App\Language::getShortLanguageName()),
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string      $phoneNumber
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($phoneCountry && !\in_array($phoneCountry, $phoneUtil->getSupportedRegions())) {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $swissNumberProto = $phoneUtil->parse($phoneNumber, $phoneCountry);
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array|bool
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            if ($phoneUtil->isValidNumber($swissNumberProto)) {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                ];
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            \App\Log::info($e->getMessage(), __CLASS__);
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

                ];
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        throw new \App\Exceptions\FieldException('LBL_INVALID_PHONE_NUMBER');
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        } catch (\libphonenumber\NumberParseException $e) {
Severity: Minor
Found in app/Fields/Phone.php by phpcodesniffer

There are no issues that match your filters.

Category
Status