railpage/railpagecore

View on GitHub
lib/Images/ImageFactory.php

Summary

Maintainability
C
1 day
Test Coverage

Function CreateImage has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public static function CreateImage($id = null, $provider = null, $options = null) {
        
        $Redis = AppCore::GetRedis(); 
        $Registry = Registry::GetInstance(); 
            
Severity: Minor
Found in lib/Images/ImageFactory.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

Method CreateImage has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function CreateImage($id = null, $provider = null, $options = null) {
        
        $Redis = AppCore::GetRedis(); 
        $Registry = Registry::GetInstance(); 
            
Severity: Minor
Found in lib/Images/ImageFactory.php - About 1 hr to fix

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

        public static function CreateCamera($id) {
            
            $Database = AppCore::GetDatabase(); 
            $Memcached = AppCore::GetMemcached(); 
            $Redis = AppCore::getRedis();
    Severity: Minor
    Found in lib/Images/ImageFactory.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

    Method CreateCamera has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function CreateCamera($id) {
            
            $Database = AppCore::GetDatabase(); 
            $Memcached = AppCore::GetMemcached(); 
            $Redis = AppCore::getRedis();
    Severity: Minor
    Found in lib/Images/ImageFactory.php - About 1 hr to fix

      Avoid too many return statements within this method.
      Open

              return $Image;
      Severity: Major
      Found in lib/Images/ImageFactory.php - About 30 mins to fix

        Avoid assigning values to variables in if clauses and the like (line '45', column '22').
        Open

            public static function CreateImage($id = null, $provider = null, $options = null) {
                
                $Redis = AppCore::GetRedis(); 
                $Registry = Registry::GetInstance(); 
                    
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        Avoid assigning values to variables in if clauses and the like (line '147', column '18').
        Open

            public static function CreateCamera($id) {
                
                $Database = AppCore::GetDatabase(); 
                $Memcached = AppCore::GetMemcached(); 
                $Redis = AppCore::getRedis();
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        Avoid assigning values to variables in if clauses and the like (line '71', column '17').
        Open

            public static function CreateImage($id = null, $provider = null, $options = null) {
                
                $Redis = AppCore::GetRedis(); 
                $Registry = Registry::GetInstance(); 
                    
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        Avoid assigning values to variables in if clauses and the like (line '219', column '14').
        Open

            public static function GetThumbnails($ids) {
                
                $Memcached = AppCore::getMemcached(); 
                $Database = (new AppCore)->getDatabaseConnection(); 
                
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        Avoid assigning values to variables in if clauses and the like (line '126', column '18').
        Open

            public static function CreateCamera($id) {
                
                $Database = AppCore::GetDatabase(); 
                $Memcached = AppCore::GetMemcached(); 
                $Redis = AppCore::getRedis();
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

                    if (!filter_var($lookup, FILTER_VALIDATE_INT)) {
                        throw new Exception("Could not find a camera ID from URL slug " . $id); 
                    }
        Severity: Major
        Found in lib/Images/ImageFactory.php and 2 other locations - About 1 hr to fix
        lib/Images/ImageFactory.php on lines 176..178
        lib/News/Factory.php on lines 47..49

        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 34.

        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 3 locations. Consider refactoring.
        Open

                    if (!filter_var($lookup, FILTER_VALIDATE_INT)) {
                        throw new Exception("Could not find a competition ID from URL slug " . $id); 
                    }
        Severity: Major
        Found in lib/Images/ImageFactory.php and 2 other locations - About 1 hr to fix
        lib/Images/ImageFactory.php on lines 134..136
        lib/News/Factory.php on lines 47..49

        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 34.

        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

                if (is_array($ids)) {
                    $ids = implode(",", $ids);
                }
        Severity: Minor
        Found in lib/Images/ImageFactory.php and 1 other location - About 55 mins to fix
        lib/News/News.php on lines 170..172

        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 29.

        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 15 locations. Consider refactoring.
        Open

            public static function CreateImage($id = null, $provider = null, $options = null) {
                
                $Redis = AppCore::GetRedis(); 
                $Registry = Registry::GetInstance(); 
                    
        Severity: Major
        Found in lib/Images/ImageFactory.php and 14 other locations - About 55 mins to fix
        lib/Downloads/Download.php on lines 384..403
        lib/Images/Images.php on lines 95..126
        lib/Links/Category.php on lines 122..133
        lib/Locations/Locations.php on lines 356..397
        lib/Locos/Factory.php on lines 90..123
        lib/Locos/LocoClass.php on lines 1038..1061
        lib/Locos/Locomotive.php on lines 327..354
        lib/Locos/Locomotive.php on lines 711..745
        lib/Locos/Locomotive.php on lines 806..817
        lib/Locos/Locomotive.php on lines 1118..1144
        lib/Locos/Locos.php on lines 995..1019
        lib/Modules/Modules.php on lines 91..112
        lib/Notifications/Notification.php on lines 465..484
        lib/Users/Utility/PasswordUtility.php on lines 68..96

        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 28.

        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 15 locations. Consider refactoring.
        Open

                        $meta['sizes'] = Images::normaliseSizes($meta['sizes']); 
        Severity: Major
        Found in lib/Images/ImageFactory.php and 14 other locations - About 35 mins to fix
        lib/Formatting/MultimediaUtility.php on lines 263..263
        lib/Images/Competition.php on lines 351..351
        lib/Images/Exif.php on lines 145..145
        lib/Images/Exif.php on lines 146..146
        lib/Images/Exif.php on lines 147..147
        lib/Images/Utility/Finder.php on lines 706..706
        lib/Images/Utility/Finder.php on lines 735..735
        lib/Locos/Utility/LocosUtility.php on lines 56..56
        lib/News/Topic.php on lines 233..233
        lib/News/Topic.php on lines 290..290
        lib/News/Topic.php on lines 292..292
        lib/Newsletters/Weekly.php on lines 412..412
        lib/Newsletters/Weekly.php on lines 414..414
        lib/Users/Timeline.php on lines 177..177

        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 22.

        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

        Blank line found at end of control structure
        Open

                        
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Function closing brace must go on the next line following the body; found 1 blank lines before brace
        Open

            }
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Function closing brace must go on the next line following the body; found 1 blank lines before brace
        Open

            }
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                    } catch (Exception $e) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                } catch (Exception $e) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at end of control structure
        Open

                    
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                if (!filter_var($id, FILTER_VALIDATE_INT)) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Function closing brace must go on the next line following the body; found 1 blank lines before brace
        Open

            }
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at end of control structure
        Open

                        
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Function closing brace must go on the next line following the body; found 1 blank lines before brace
        Open

            }
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                if (!filter_var($id, FILTER_VALIDATE_INT)) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at end of control structure
        Open

                    
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                if ($id != null && $provider == null) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                        if (!$Image = $Redis->fetch($cachekey)) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at end of control structure
        Open

                            
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                    foreach ($Database->fetchAll($query) as $row) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at end of control structure
        Open

                    
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Blank line found at start of control structure
        Open

                if (!$return = $Memcached->fetch($cachekey)) {
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        Function closing brace must go on the next line following the body; found 1 blank lines before brace
        Open

            }
        Severity: Minor
        Found in lib/Images/ImageFactory.php by phpcodesniffer

        There are no issues that match your filters.

        Category
        Status