visavi/rotor

View on GitHub
app/helpers.php

Summary

Maintainability
F
5 days
Test Coverage

File helpers.php has 1179 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use App\Classes\BBCode;
use App\Classes\Calendar;
use App\Classes\CloudFlare;
Severity: Major
Found in app/helpers.php - About 3 days to fix

    Method icons has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function icons(string $ext): HtmlString
    {
        switch ($ext) {
            case 'php':
                $ico = 'fa-regular fa-file-code';
    Severity: Major
    Found in app/helpers.php - About 2 hrs to fix

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

      function icons(string $ext): HtmlString
      {
          switch ($ext) {
              case 'php':
                  $ico = 'fa-regular fa-file-code';
      Severity: Minor
      Found in app/helpers.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 resizeProcess has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function resizeProcess(?string $path, array $params = []): array
      {
          if (empty($params['alt'])) {
              $params['alt'] = basename($path);
          }
      Severity: Minor
      Found in app/helpers.php - About 1 hr to fix

        Method dateFixed has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function dateFixed(
            DateTimeInterface|int|null $timestamp,
            string $format = 'd.m.Y / H:i',
            bool $original = false,
        ): string {
        Severity: Minor
        Found in app/helpers.php - About 1 hr to fix

          Method restatement has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function restatement(string $mode)
          {
              switch ($mode) {
                  case 'forums':
                      DB::update('update topics set count_posts = (select count(*) from posts where topics.id = posts.topic_id)');
          Severity: Minor
          Found in app/helpers.php - About 1 hr to fix

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

            function restatement(string $mode)
            {
                switch ($mode) {
                    case 'forums':
                        DB::update('update topics set count_posts = (select count(*) from posts where topics.id = posts.topic_id)');
            Severity: Minor
            Found in app/helpers.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 deleteDir has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            function deleteDir(string $dir)
            {
                if (file_exists($dir)) {
                    if ($files = glob($dir . '/*')) {
                        foreach ($files as $file) {
            Severity: Minor
            Found in app/helpers.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

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

            function resizeProcess(?string $path, array $params = []): array
            {
                if (empty($params['alt'])) {
                    $params['alt'] = basename($path);
                }
            Severity: Minor
            Found in app/helpers.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

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

            function sendNotify(string $text, string $url, string $title)
            {
                /*$parseText = preg_replace('|\[quote(.*?)\](.*?)\[/quote\]|s', '', $text);*/
                preg_match_all('/(?<=^|\s|=)@([\w\-]+)/', $text, $matches);
            
            
            Severity: Minor
            Found in app/helpers.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

            Avoid too many return statements within this method.
            Open

                return $num . ' ' . $forms[2];
            Severity: Major
            Found in app/helpers.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return round($num / 1000, 1) . 'K';
              Severity: Major
              Found in app/helpers.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                    return $num;
                Severity: Major
                Found in app/helpers.php - About 30 mins to fix

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

                  function getQueryLog(): array
                  {
                      $queries = DB::getQueryLog();
                  
                      $formattedQueries = [];
                  Severity: Minor
                  Found in app/helpers.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

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

                  function plural(int $num, mixed $forms): string
                  {
                      if (! is_array($forms)) {
                          $forms = explode(',', $forms);
                      }
                  Severity: Minor
                  Found in app/helpers.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

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

                  function statsPhotos(): string
                  {
                      return Cache::remember('statPhotos', 900, static function () {
                          $stat = Photo::query()->count();
                          $totalNew = Photo::query()->where('created_at', '>', strtotime('-1 day', SITETIME))->count();
                  Severity: Major
                  Found in app/helpers.php and 3 other locations - About 1 hr to fix
                  app/helpers.php on lines 520..531
                  app/helpers.php on lines 631..639
                  app/helpers.php on lines 684..695

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

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

                  function statsBlog(): string
                  {
                      return Cache::remember('statArticles', 900, static function () {
                          $stat = Article::query()->count();
                          $totalNew = Article::query()->where('created_at', '>', strtotime('-1 day', SITETIME))->count();
                  Severity: Major
                  Found in app/helpers.php and 3 other locations - About 1 hr to fix
                  app/helpers.php on lines 505..513
                  app/helpers.php on lines 520..531
                  app/helpers.php on lines 684..695

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

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

                  function statsNews(): string
                  {
                      return Cache::remember('statNews', 300, static function () {
                          $total = News::query()->count();
                  
                  
                  Severity: Major
                  Found in app/helpers.php and 3 other locations - About 1 hr to fix
                  app/helpers.php on lines 505..513
                  app/helpers.php on lines 631..639
                  app/helpers.php on lines 684..695

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

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

                  function statsChat(): string
                  {
                      return Cache::remember('statChat', 3600, static function () {
                          $total = Chat::query()->count();
                  
                  
                  Severity: Major
                  Found in app/helpers.php and 3 other locations - About 1 hr to fix
                  app/helpers.php on lines 505..513
                  app/helpers.php on lines 520..531
                  app/helpers.php on lines 631..639

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

                  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

                  There are no issues that match your filters.

                  Category
                  Status