owncloud/core

View on GitHub
lib/private/Tags.php

Summary

Maintainability
F
5 days
Test Coverage

File Tags.php has 535 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Bernhard Reiter <ockham@raz.or.at>
 * @author derkostka <sebastian.kostka@gmail.com>
 * @author Joas Schilling <coding@schilljs.com>
Severity: Major
Found in lib/private/Tags.php - About 1 day to fix

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

        public function getIdsForTag($tag) {
            $result = null;
            $tagId = false;
            if (\is_numeric($tag)) {
                $tagId = $tag;
    Severity: Minor
    Found in lib/private/Tags.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

    Tags has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Tags implements \OCP\ITags {
        /**
         * Tags
         *
         * @var array
    Severity: Minor
    Found in lib/private/Tags.php - About 3 hrs to fix

      Function save has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function save() {
              if (\is_array($this->tags)) {
                  foreach ($this->tags as $tag) {
                      try {
                          if (!$this->mapper->tagExists($tag)) {
      Severity: Minor
      Found in lib/private/Tags.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 delete has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public function delete($names) {
              if (!\is_array($names)) {
                  $names = [$names];
              }
      
      
      Severity: Minor
      Found in lib/private/Tags.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 getIdsForTag has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getIdsForTag($tag) {
              $result = null;
              $tagId = false;
              if (\is_numeric($tag)) {
                  $tagId = $tag;
      Severity: Major
      Found in lib/private/Tags.php - About 2 hrs to fix

        Method save has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function save() {
                if (\is_array($this->tags)) {
                    foreach ($this->tags as $tag) {
                        try {
                            if (!$this->mapper->tagExists($tag)) {
        Severity: Minor
        Found in lib/private/Tags.php - About 1 hr to fix

          Method post_deleteUser has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function post_deleteUser($arguments) {
                  // Find all objectid/tagId pairs.
                  $result = null;
                  try {
                      $stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
          Severity: Minor
          Found in lib/private/Tags.php - About 1 hr to fix

            Method delete has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function delete($names) {
                    if (!\is_array($names)) {
                        $names = [$names];
                    }
            
            
            Severity: Minor
            Found in lib/private/Tags.php - About 1 hr to fix

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

                  public static function post_deleteUser($arguments) {
                      // Find all objectid/tagId pairs.
                      $result = null;
                      try {
                          $stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
              Severity: Minor
              Found in lib/private/Tags.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 getTagsForObjects has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getTagsForObjects(array $objIds) {
                      $entries = [];
              
                      try {
                          $conn = \OC::$server->getDatabaseConnection();
              Severity: Minor
              Found in lib/private/Tags.php - About 1 hr to fix

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

                    public function rename($from, $to) {
                        $from = \trim($from);
                        $to = \trim($to);
                
                        if ($to === '' || $from === '') {
                Severity: Minor
                Found in lib/private/Tags.php - About 1 hr to fix

                  Method tagAs has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function tagAs($objid, $tag) {
                          if (\is_string($tag) && !\is_numeric($tag)) {
                              $tag = \trim($tag);
                              if ($tag === '') {
                                  \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
                  Severity: Minor
                  Found in lib/private/Tags.php - About 1 hr to fix

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

                        public function getTagsForObjects(array $objIds) {
                            $entries = [];
                    
                            try {
                                $conn = \OC::$server->getDatabaseConnection();
                    Severity: Minor
                    Found in lib/private/Tags.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 tagAs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function tagAs($objid, $tag) {
                            if (\is_string($tag) && !\is_numeric($tag)) {
                                $tag = \trim($tag);
                                if ($tag === '') {
                                    \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
                    Severity: Minor
                    Found in lib/private/Tags.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 addMultiple has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function addMultiple($names, $sync=false, $id = null) {
                            if (!\is_array($names)) {
                                $names = [$names];
                            }
                            $names = \array_map('trim', $names);
                    Severity: Minor
                    Found in lib/private/Tags.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

                    Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public function __construct(TagMapper $mapper, $user, $type, array $defaultTags = [], $includeShared = false) {
                    Severity: Minor
                    Found in lib/private/Tags.php - About 35 mins to fix

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

                          public function rename($from, $to) {
                              $from = \trim($from);
                              $to = \trim($to);
                      
                              if ($to === '' || $from === '') {
                      Severity: Minor
                      Found in lib/private/Tags.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 true;
                      Severity: Major
                      Found in lib/private/Tags.php - About 30 mins to fix

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

                            public function unTag($objid, $tag) {
                                if (\is_string($tag) && !\is_numeric($tag)) {
                                    $tag = \trim($tag);
                                    if ($tag === '') {
                                        \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG);
                        Severity: Minor
                        Found in lib/private/Tags.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 2 locations. Consider refactoring.
                        Open

                                try {
                                    $stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
                                        . 'WHERE `uid` = ?');
                                    $result = $stmt->execute([$arguments['uid']]);
                                    if (\OCP\DB::isError($result)) {
                        Severity: Major
                        Found in lib/private/Tags.php and 1 other location - About 2 hrs to fix
                        lib/private/Tags.php on lines 570..580

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

                        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

                                try {
                                    $stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
                                        . 'WHERE `uid` = ?');
                                    $result = $stmt->execute([$arguments['uid']]);
                                    if (\OCP\DB::isError($result)) {
                        Severity: Major
                        Found in lib/private/Tags.php and 1 other location - About 2 hrs to fix
                        lib/private/Tags.php on lines 532..545

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

                        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