whiteCube/lingua

View on GitHub

Showing 36 of 36 total issues

File languages.php has 2216 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
* This file should always return an array containing
* the languages data. Please follow the structure 
Severity: Major
Found in languages.php - About 6 days to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    <?php 
    
    namespace WhiteCube\Lingua;
    
    class W3cConverter extends ComponentConverter implements ConverterInterface
    Severity: Major
    Found in src/Lingua/W3cConverter.php and 1 other location - About 6 hrs to fix
    src/Lingua/PhpConverter.php on lines 1..26

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 217.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    <?php 
    
    namespace WhiteCube\Lingua;
    
    class PhpConverter extends ComponentConverter implements ConverterInterface
    Severity: Major
    Found in src/Lingua/PhpConverter.php and 1 other location - About 6 hrs to fix
    src/Lingua/W3cConverter.php on lines 1..26

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 217.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function find has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function find($format, $value)
        {
            $instance = self::getInstance();
            foreach ($instance->languages as $language) {
                if(!isset($language[$format])) continue;
    Severity: Minor
    Found in src/Lingua/LanguagesRepository.php - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    The class Iso_639_2tConverter is not named in CamelCase.
    Open

    class Iso_639_2tConverter extends Converter implements ConverterInterface
    {
        public static function check($format)
        {
            if(preg_match('/^([A-Za-z]{3})$/', static::prepare($format))) return true;
    Severity: Minor
    Found in src/Lingua/Iso_639_2tConverter.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The class Iso_639_2bConverter is not named in CamelCase.
    Open

    class Iso_639_2bConverter extends Converter implements ConverterInterface
    {
        public static function check($format)
        {
            if(preg_match('/^([A-Za-z]{3})$/', static::prepare($format))) return true;
    Severity: Minor
    Found in src/Lingua/Iso_639_2bConverter.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The class Iso_639_3Converter is not named in CamelCase.
    Open

    class Iso_639_3Converter extends Converter implements ConverterInterface
    {
        public function __toString()
        {
            $string = $this->original['code'] ?? $this->original['full'];
    Severity: Minor
    Found in src/Lingua/Iso_639_3Converter.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The class Iso_639_1Converter is not named in CamelCase.
    Open

    class Iso_639_1Converter extends Converter implements ConverterInterface
    {
        public static function check($format)
        {
            if(preg_match('/^([A-Za-z]{2})$/', static::prepare($format))) return true;
    Severity: Minor
    Found in src/Lingua/Iso_639_1Converter.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    Function guess has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function guess(string $format)
        {
            $matches = [];
            foreach (self::$converters as $key => $converter) {
                if(!call_user_func_array($converter . '::check', [$format])) continue;
    Severity: Minor
    Found in src/Lingua/Service.php - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function format has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function format(ConverterInterface $converter)
        {
            if(!$converter->repository) {
                throw new \Exception('Language "' . $converter . '" could not be converted to its english name since it is not registered in the Lingua repository');
            }
    Severity: Minor
    Found in src/Lingua/NameConverter.php - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Missing class import via use statement (line '60', column '23').
    Open

                throw new \Exception('Lingua\'s languages repository could not be loaded');
    Severity: Minor
    Found in src/Lingua/LanguagesRepository.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 '105', column '23').
    Open

                throw new \Exception('Instantiation methods should begin with "create"');
    Severity: Minor
    Found in src/Lingua/Service.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 '16', column '23').
    Open

                throw new \Exception('Unable to find language named "' . $this->original . '"');
    Severity: Minor
    Found in src/Lingua/NameConverter.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 '33', column '23').
    Open

                throw new \Exception('Language "' . $converter . '" could not be converted to its native name since it is not registered in the Lingua repository');
    Severity: Minor
    Found in src/Lingua/NativeConverter.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 '16', column '23').
    Open

                throw new \Exception('Unable to find native language named "' . $this->original . '"');
    Severity: Minor
    Found in src/Lingua/NativeConverter.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 '51', column '21').
    Open

            $item = new \stdClass();
    Severity: Minor
    Found in src/Lingua/Converter.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 '33', column '23').
    Open

                throw new \Exception('Language "' . $converter . '" could not be converted to its english name since it is not registered in the Lingua repository');
    Severity: Minor
    Found in src/Lingua/NameConverter.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 '64', column '19').
    Open

            throw new \Exception('Call to undefined Lingua method "' . $method . '"');
    Severity: Minor
    Found in src/Lingua/Service.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 '122', column '23').
    Open

                throw new \Exception('Call to undefined "'. $prefix . '" Lingua method');
    Severity: Minor
    Found in src/Lingua/Service.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 '94', column '19').
    Open

            throw new \Exception('Unable to guess the format for input string "' . $code . '"');
    Severity: Minor
    Found in src/Lingua/Service.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

    Severity
    Category
    Status
    Source
    Language