GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CackleSync   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 9 1
A update() 0 8 1
A saveItems() 0 14 3
A process() 0 11 2
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package 
8
 */
9
Yii::import('ext.cackle.models.*');
10
Yii::import('ext.cackle.components.*');
11
12
final class CackleSync
13
{
14
  private $limit;
15
16
  /**
17
   * @var CackleManagerInterface
18
   */
19
  private $manager;
20
21
  /**
22
   * @param CackleManagerInterface $manager
23
   * @param int $limit default 50
24
   */
25
  public function __construct(CackleManagerInterface $manager, $limit = 50)
26
  {
27
    $this->manager = $manager;
28
    $this->limit = $limit;
29
  }
30
31
  /**
32
   * @var CackleManagerInterface $manager
33
   */
34
  public function create()
35
  {
36
    Yii::app()->getDb()->beginTransaction();
37
38
    $this->manager->clearAll();
39
    $this->process();
40
41
    Yii::app()->getDb()->currentTransaction->commit();
42
  }
43
44
  public function update()
45
  {
46
    Yii::app()->getDb()->beginTransaction();
47
48
    $this->process($this->manager->getLastModified());
49
50
    Yii::app()->getDb()->currentTransaction->commit();
51
  }
52
53
  /**
54
   * @param CackleManagerInterface $manager
55
   * @param CackleResponseReview[] $items
56
   * @param array $idsForUpdate
57
   */
58
  protected function saveItems($manager, array $items, $idsForUpdate = array())
59
  {
60
    foreach($items as $item)
61
    {
62
      if( !isset($idsForUpdate[$item->id]) )
0 ignored issues
show
Bug introduced by
Accessing id on the interface CackleResponseReview suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
63
      {
64
        $manager->insert($item);
65
      }
66
      else
67
      {
68
        $manager->update($item);
69
      }
70
    }
71
  }
72
73
  protected function process($modified = null)
74
  {
75
    $idsForUpdate = $this->manager->getIdsForUpdate();
76
    $defaultItems = $this->manager->getRemoteItems(0, $this->limit, $modified);
77
78
    for($page = 0; $page < $defaultItems->totalPages; $page++)
79
    {
80
      $items = $this->manager->getRemoteItems($page, $this->limit, $modified);
81
      $this->saveItems($this->manager, $items->content, $idsForUpdate);
82
    }
83
  }
84
}