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 ( 32efce...e00f81 )
by De
02:05
created

BatchInsert::isValidationEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    private $isValidationEnabled = true;
21
22
    /**
23
     * Used for validating array of data
24
     * @var Document
25
     */
26
    private static $validator;
27
28
    public function __construct(Collection $collection, $writeConcern = null, $timeout = null, $ordered = null)
29
    {
30
        parent::__construct($collection, $writeConcern, $timeout, $ordered);
31
32
        self::$validator = $collection->createDocument();
33
    }
34
35
    public function enableValidation()
36
    {
37
        $this->isValidationEnabled = true;
38
        return $this;
39
    }
40
41
    public function disableValidation()
42
    {
43
        $this->isValidationEnabled = false;
44
        return $this;
45
    }
46
47
    public function isValidationEnabled()
48
    {
49
        return $this->isValidationEnabled;
50
    }
51
52
    /**
53
     * @deprecated use self::isValidationEnabled()
54
     * @return bool
55
     */
56
    public function isValidationEbabled()
57
    {
58
        return $this->isValidationEnabled;
59
    }
60
61
    public function insert(array $document)
62
    {
63
        if (!$this->isValidationEnabled) {
64
            self::$validator->merge($document);
65
            $isValid = self::$validator->isValid();
66
            self::$validator->reset();
67
68
            if (!$isValid) {
69
                throw new InvalidDocumentException('Document is invalid on batch insert');
70
            }
71
        }
72
73
        $this->add($document);
74
        return $this;
75
    }
76
}
77