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.
Completed
Push — master ( 951ad1...29ba67 )
by Alexey
08:55
created

ManyRecordInserter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 48.15%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 61
ccs 13
cts 27
cp 0.4815
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addAttributes() 0 4 1
A setAttributesList() 0 4 1
A save() 0 20 4
A onSave() 0 4 1
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2016 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 */
8
class ManyRecordInserter extends CComponent
9
{
10
  /**
11
   * @var CDbCommandBuilder
12
   */
13
  private $builder;
14
15
  private $data = array();
16
17
  private $table;
18
19
  private $insertChunkSize;
20
21 24
  public function __construct($table, $insertChunkSize = 25000)
22
  {
23 24
    $this->table = $table;
24 24
    $this->insertChunkSize = $insertChunkSize;
25 24
    $this->builder = Yii::app()->db->commandBuilder;
26 24
  }
27
28
  public function addAttributes($attributes)
29
  {
30
    $this->data[] = $attributes;
31
  }
32
33
  public function setAttributesList($attributesList)
34
  {
35
    $this->data = $attributesList;
36
  }
37
38
  /**
39
   * @param bool $writeNow = false
40
   *
41
   * @return int $count
42
   */
43 4
  public function save($writeNow = false)
44
  {
45 4
    if( empty($this->data) )
46 4
    {
47 4
      $this->onSave(new CEvent($this, array('count' => 0)));
48 4
      return 0;
49
50
    }
51
52
    if( count($this->data) >= $this->insertChunkSize || $writeNow )
53
    {
54
      $command = $this->builder->createMultipleInsertCommand($this->table, $this->data);
55
      $count = $command->query()->count();
56
57
      $this->data = array();
58
      $this->onSave(new CEvent($this, array('count' => $count)));
59
60
      return $count;
61
    }
62
  }
63
64 4
  public function onSave(CEvent $event)
65
  {
66 4
     $this->raiseEvent('onSave', $event);
67
  }
68
}