Completed
Push — master ( 09b86b...ba0798 )
by Andreas
20:05 queued 12s
created

AutoGenerator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.2559
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Id;
6
7
use Doctrine\ODM\MongoDB\DocumentManager;
8
use MongoDB\BSON\ObjectId;
9
use const E_USER_DEPRECATED;
10
use function sprintf;
11
use function trigger_error;
12
13
/**
14
 * AutoGenerator generates a native ObjectId
15
 *
16
 * @final
17
 */
18
class AutoGenerator extends AbstractIdGenerator
19
{
20 1415 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22 1415
        if (self::class === static::class) {
23 1415
            return;
24
        }
25
26
        @trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
27
    }
28
29
    /** @inheritDoc */
30 552
    public function generate(DocumentManager $dm, object $document)
31
    {
32 552
        return new ObjectId();
33
    }
34
}
35