owncloud/core

View on GitHub
apps/dav/lib/CardDAV/CardDavBackend.php

Summary

Maintainability
F
4 days
Test Coverage

File CardDavBackend.php has 591 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 * @author Björn Schießle <bjoern@schiessle.org>
 * @author Georg Ehrke <georg@owncloud.com>
Severity: Major
Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 day to fix

    CardDavBackend has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CardDavBackend implements BackendInterface, SyncSupport {
        /** @var Principal */
        private $principalBackend;
    
        /** @var string */
    Severity: Minor
    Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 3 hrs to fix

      Method getChangesForAddressBook has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) {
              // Current synctoken
              $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?');
              $stmt->execute([ $addressBookId ]);
              $currentToken = $stmt->fetchColumn();
      Severity: Minor
      Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

        Method searchEx has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function searchEx($addressBookId, $pattern, $searchProperties, $options, $limit = 100, $offset = 0) {
                $query = $this->db->getQueryBuilder();
                $cardIdSelect = $this->db->getQueryBuilder();
                $cardIdSelect->selectDistinct('cp.cardid')->from($this->dbCardsPropertiesTable, 'cp');
        
        
        Severity: Minor
        Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

          Method getAddressBooksForUser has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getAddressBooksForUser($principalUri) {
                  $addressBooks = $this->getUsersOwnAddressBooks($principalUri);
          
                  // query for shared calendars
                  $principals = $this->principalBackend->getGroupMembership($principalUri, true);
          Severity: Minor
          Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

            Method createAddressBook has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function createAddressBook($principalUri, $url, array $properties) {
                    $values = [
                        'displayname' => null,
                        'description' => null,
                        'principaluri' => $principalUri,
            Severity: Minor
            Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

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

                  public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) {
                      // Current synctoken
                      $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?');
                      $stmt->execute([ $addressBookId ]);
                      $currentToken = $stmt->fetchColumn();
              Severity: Minor
              Found in apps/dav/lib/CardDAV/CardDavBackend.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 updateProperties has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) {
                      $cardId = $this->getCardId($addressBookId, $cardUri);
                      $vCard = $this->readCard($vCardSerialized);
              
                      $this->purgeProperties($addressBookId, $cardId);
              Severity: Minor
              Found in apps/dav/lib/CardDAV/CardDavBackend.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 updateProperties has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) {
                      $cardId = $this->getCardId($addressBookId, $cardUri);
                      $vCard = $this->readCard($vCardSerialized);
              
                      $this->purgeProperties($addressBookId, $cardId);
              Severity: Minor
              Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

                Method updateAddressBook has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
                        $supportedProperties = [
                            '{DAV:}displayname',
                            '{' . Plugin::NS_CARDDAV . '}addressbook-description',
                        ];
                Severity: Minor
                Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

                  Method deleteCard has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function deleteCard($addressBookId, $cardUri) {
                          try {
                              $cardId = $this->getCardId($addressBookId, $cardUri);
                          } catch (\InvalidArgumentException $e) {
                              $cardId = null;
                  Severity: Minor
                  Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 1 hr to fix

                    Method searchEx has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public function searchEx($addressBookId, $pattern, $searchProperties, $options, $limit = 100, $offset = 0) {
                    Severity: Minor
                    Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 45 mins to fix

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

                          public function search($addressBookId, $pattern, $searchProperties, $limit = 100, $offset = 0) {
                      Severity: Minor
                      Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 35 mins to fix

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

                                IDBConnection $db,
                                Principal $principalBackend,
                                GroupPrincipalBackend $groupPrincipalBackend,
                                EventDispatcherInterface $dispatcher = null,
                                $legacyMode = false
                        Severity: Minor
                        Found in apps/dav/lib/CardDAV/CardDavBackend.php - About 35 mins to fix

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

                                  if ($syncToken) {
                                      $query = 'SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`';
                          
                                      // Fetching all changes
                                      $stmt = $this->db->prepare($query, $limit ?: null, $limit ? 0 : null);
                          Severity: Major
                          Found in apps/dav/lib/CardDAV/CardDavBackend.php and 1 other location - About 7 hrs to fix
                          apps/dav/lib/CalDAV/CalDavBackend.php on lines 1144..1179

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

                          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

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

                              private function convertPrincipal($principalUri, $toV2 = null) {
                                  if ($this->principalBackend->getPrincipalPrefix() === 'principals') {
                                      list(, $name) = \Sabre\Uri\split($principalUri);
                                      $toV2 = $toV2 === null ? !$this->legacyMode : $toV2;
                                      if ($toV2) {
                          Severity: Minor
                          Found in apps/dav/lib/CardDAV/CardDavBackend.php and 1 other location - About 40 mins to fix
                          apps/dav/lib/CalDAV/CalDavBackend.php on lines 1661..1671

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

                          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