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.

BatchInsert   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A enableValidation() 0 5 1
A disableValidation() 0 5 1
A isValidationEnabled() 0 4 1
A insert() 0 16 3
1
<?php
2
3
/**
4
 * This file is part of the PHPMongo package.
5
 *
6
 * (c) Dmytro Sokil <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sokil\Mongo;
13
14
use Sokil\Mongo\Document\InvalidDocumentException;
15
16
class BatchInsert extends BatchOperation
17
{
18
    protected $batchClass = '\MongoInsertBatch';
19
20
    /**
21
     * @var bool
22
     */
23
    private $isValidationEnabled = true;
24
25
    /**
26
     * Used for validating array of data
27
     * @var Document
28
     */
29
    private $validator;
30
31
    public function init()
32
    {
33
        $this->validator = $this->collection->createDocument();
34
    }
35
36
    /**
37
     * @return $this
38
     */
39
    public function enableValidation()
40
    {
41
        $this->isValidationEnabled = true;
42
        return $this;
43
    }
44
45
    /**
46
     * @return $this
47
     */
48
    public function disableValidation()
49
    {
50
        $this->isValidationEnabled = false;
51
        return $this;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function isValidationEnabled()
58
    {
59
        return $this->isValidationEnabled;
60
    }
61
62
    /**
63
     * @param array $document
64
     * @return $this
65
     * @throws InvalidDocumentException
66
     */
67
    public function insert(array $document)
68
    {
69
        // validate
70
        if ($this->isValidationEnabled) {
71
            $this->validator->merge($document);
72
            $isValid = $this->validator->isValid();
73
            $this->validator->reset();
74
            if (!$isValid) {
75
                throw new InvalidDocumentException('Document is invalid on batch insert');
76
            }
77
        }
78
79
        // add to batch
80
        $this->add($document);
81
        return $this;
82
    }
83
}
84