tacnoman/thumcno

View on GitHub
src/Tacnoman/ThumcnoServer.php

Summary

Maintainability
F
1 wk
Test Coverage

File ThumcnoServer.php has 1131 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Tacnoman;

//These are now disabled by default because the file sizes of PNGs (and GIFs) are much smaller than we used to generate.
Severity: Major
Found in src/Tacnoman/ThumcnoServer.php - About 2 days to fix

    Function processImageAndWriteToCache has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function processImageAndWriteToCache($localImage)
        {
            $config = Config::getInstance();
            $sData = getimagesize($localImage);
            $origType = $sData[2];
    Severity: Minor
    Found in src/Tacnoman/ThumcnoServer.php - About 1 day 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 processImageAndWriteToCache has 249 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function processImageAndWriteToCache($localImage)
        {
            $config = Config::getInstance();
            $sData = getimagesize($localImage);
            $origType = $sData[2];
    Severity: Major
    Found in src/Tacnoman/ThumcnoServer.php - About 1 day to fix

      ThumcnoServer has 40 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class ThumcnoServer
      {
          public $src = '';
          public $is404 = false;
          public $docRoot = '';
      Severity: Minor
      Found in src/Tacnoman/ThumcnoServer.php - About 5 hrs to fix

        Function getLocalImagePath has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function getLocalImagePath($src)
            {
                $src = ltrim($src, '/'); //strip off the leading '/'
                if (!$this->docRoot) {
                    Logger::error('We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.');
        Severity: Minor
        Found in src/Tacnoman/ThumcnoServer.php - About 3 hrs 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 getURL has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function getURL($url, $tempfile)
            {
                $config = Config::getInstance();
                $this->lastURLError = false;
                $url = preg_replace('/ /', '%20', $url);
        Severity: Minor
        Found in src/Tacnoman/ThumcnoServer.php - About 3 hrs 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 getURL has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function getURL($url, $tempfile)
            {
                $config = Config::getInstance();
                $this->lastURLError = false;
                $url = preg_replace('/ /', '%20', $url);
        Severity: Major
        Found in src/Tacnoman/ThumcnoServer.php - About 2 hrs to fix

          Function validateExternalImage has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public function validateExternalImage()
              {
                  $config = Config::getInstance();
                  if ($this->isURL && (!$config->appConfigs['allow_external'])) {
                      $this->error('You are not allowed to fetch images from an external website.');
          Severity: Minor
          Found in src/Tacnoman/ThumcnoServer.php - About 2 hrs 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 cleanCache has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function cleanCache()
              {
                  $config = Config::getInstance();
                  if ($config->appConfigs['file_cache_time_between_cleans'] < 0) {
                      return;
          Severity: Minor
          Found in src/Tacnoman/ThumcnoServer.php - About 2 hrs 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 getLocalImagePath has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function getLocalImagePath($src)
              {
                  $src = ltrim($src, '/'); //strip off the leading '/'
                  if (!$this->docRoot) {
                      Logger::error('We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.');
          Severity: Major
          Found in src/Tacnoman/ThumcnoServer.php - About 2 hrs to fix

            Function tryServerCache has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function tryServerCache()
                {
                    $config = Config::getInstance();
                    Logger::info('Trying server cache');
                    if (file_exists($this->cachefile)) {
            Severity: Minor
            Found in src/Tacnoman/ThumcnoServer.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 serveWebshot has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function serveWebshot()
                {
                    Logger::notice('Starting serveWebshot');
                    $instr = 'Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots.';
                    if (!is_file(WEBSHOT_CUTYCAPT)) {
            Severity: Minor
            Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

              Function handleErrors has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function handleErrors()
                  {
                      if ($this->haveErrors()) {
                          $config = Config::getInstance();
                          if ($config->appConfigs['not_found_image'] && $this->is404()) {
              Severity: Minor
              Found in src/Tacnoman/ThumcnoServer.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

              Function tryBrowserCache has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function tryBrowserCache()
                  {
                      $config = Config::getInstance();
                      if ($config->appConfigs['browser_cache_disable']) {
                          Logger::debug('Browser caching is disabled');
              Severity: Minor
              Found in src/Tacnoman/ThumcnoServer.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 tryBrowserCache has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function tryBrowserCache()
                  {
                      $config = Config::getInstance();
                      if ($config->appConfigs['browser_cache_disable']) {
                          Logger::debug('Browser caching is disabled');
              Severity: Minor
              Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

                Function getIP has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function getIP()
                    {
                        $rem = @$_SERVER['REMOTE_ADDR'];
                        $ff = @$_SERVER['HTTP_X_FORWARDED_FOR'];
                        $ci = @$_SERVER['HTTP_CLIENT_IP'];
                Severity: Minor
                Found in src/Tacnoman/ThumcnoServer.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 serveCacheFile has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function serveCacheFile()
                    {
                        Logger::notice("Serving {$this->cachefile}");
                        if (!is_file($this->cachefile)) {
                            $this->error("serveCacheFile called in thumcno but we couldn't find the cached file.");
                Severity: Minor
                Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

                  Method cleanCache has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function cleanCache()
                      {
                          $config = Config::getInstance();
                          if ($config->appConfigs['file_cache_time_between_cleans'] < 0) {
                              return;
                  Severity: Minor
                  Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

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

                        public function run()
                        {
                            $config = Config::getInstance();
                            if ($this->isURL) {
                                if (!$config->appConfigs['allow_external']) {
                    Severity: Minor
                    Found in src/Tacnoman/ThumcnoServer.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 tryServerCache has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function tryServerCache()
                        {
                            $config = Config::getInstance();
                            Logger::info('Trying server cache');
                            if (file_exists($this->cachefile)) {
                    Severity: Minor
                    Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

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

                          protected function serveExternalImage()
                          {
                              if (!preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+/i', $this->src)) {
                                  $this->error('Invalid URL supplied.');
                      
                      
                      Severity: Minor
                      Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

                        Consider simplifying this complex logical expression.
                        Open

                                if ($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)) {
                                    $exec = OPTIPNG_PATH;
                                    Logger::debug("optipng'ing $tempfile");
                                    $presize = filesize($tempfile);
                                    $out = `$exec -o1 $tempfile`; //you can use up to -o7 but it really slows things down
                        Severity: Major
                        Found in src/Tacnoman/ThumcnoServer.php - About 1 hr to fix

                          Function calcDocRoot has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function calcDocRoot()
                              {
                                  $docRoot = @$_SERVER['DOCUMENT_ROOT'];
                                  if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
                                      $docRoot = LOCAL_FILE_BASE_DIRECTORY;
                          Severity: Minor
                          Found in src/Tacnoman/ThumcnoServer.php - About 55 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 setCacheDirectory has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function setCacheDirectory()
                              {
                                  $config = Config::getInstance();
                                  if ($config->appConfigs['file_cache_directory']) {
                                      if (!is_dir($config->appConfigs['file_cache_directory'])) {
                          Severity: Minor
                          Found in src/Tacnoman/ThumcnoServer.php - About 55 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 serveWebshot has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function serveWebshot()
                              {
                                  Logger::notice('Starting serveWebshot');
                                  $instr = 'Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots.';
                                  if (!is_file(WEBSHOT_CUTYCAPT)) {
                          Severity: Minor
                          Found in src/Tacnoman/ThumcnoServer.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

                          Avoid too many return statements within this method.
                          Open

                                              return $real;
                          Severity: Major
                          Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return false;
                            Severity: Major
                            Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return false;
                              Severity: Major
                              Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return $this->error('Could not get a lock for writing.');
                                Severity: Major
                                Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return false;
                                  Severity: Major
                                  Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return false;
                                    Severity: Major
                                    Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return true;
                                      Severity: Major
                                      Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return true;
                                        Severity: Major
                                        Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return $this->serveCacheFile();
                                          Severity: Major
                                          Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return $ci;
                                            Severity: Major
                                            Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return 'UNKNOWN';
                                              Severity: Major
                                              Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return $this->error('Could not open the lockfile for writing an image.');
                                                Severity: Major
                                                Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return true;
                                                  Severity: Major
                                                  Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                    return false;
                                                    Severity: Major
                                                    Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return false;
                                                      Severity: Major
                                                      Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return false;
                                                        Severity: Major
                                                        Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return false;
                                                          Severity: Major
                                                          Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                        return true;
                                                            Severity: Major
                                                            Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return false;
                                                              Severity: Major
                                                              Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                return $ff;
                                                                Severity: Major
                                                                Found in src/Tacnoman/ThumcnoServer.php - About 30 mins to fix

                                                                  Function serveCacheFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                  Open

                                                                      protected function serveCacheFile()
                                                                      {
                                                                          Logger::notice("Serving {$this->cachefile}");
                                                                          if (!is_file($this->cachefile)) {
                                                                              $this->error("serveCacheFile called in thumcno but we couldn't find the cached file.");
                                                                  Severity: Minor
                                                                  Found in src/Tacnoman/ThumcnoServer.php - About 25 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

                                                                  There are no issues that match your filters.

                                                                  Category
                                                                  Status