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::onSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
}