doctrine /
mongodb-odm
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Doctrine\ODM\MongoDB\Benchmark\Document; |
||
| 6 | |||
| 7 | use DateTimeImmutable; |
||
| 8 | use Doctrine\ODM\MongoDB\Benchmark\BaseBench; |
||
| 9 | use Documents\Account; |
||
| 10 | use Documents\Address; |
||
| 11 | use Documents\Group; |
||
| 12 | use Documents\Phonenumber; |
||
| 13 | use Documents\User; |
||
| 14 | use MongoDB\BSON\ObjectId; |
||
| 15 | use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
||
| 16 | use PhpBench\Benchmark\Metadata\Annotations\Warmup; |
||
| 17 | use function assert; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @BeforeMethods({"init"}, extend=true) |
||
| 21 | */ |
||
| 22 | final class LoadDocumentBench extends BaseBench |
||
| 23 | { |
||
| 24 | /** @var ObjectId */ |
||
| 25 | private static $userId; |
||
| 26 | |||
| 27 | public function init() |
||
| 28 | { |
||
| 29 | self::$userId = new ObjectId(); |
||
| 30 | |||
| 31 | $account = new Account(); |
||
|
0 ignored issues
–
show
|
|||
| 32 | $account->setName('alcaeus'); |
||
| 33 | |||
| 34 | $address = new Address(); |
||
| 35 | $address->setAddress('Redacted'); |
||
|
0 ignored issues
–
show
The method
setAddress() does not seem to exist on object<Documents\Address>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 36 | $address->setCity('Munich'); |
||
| 37 | |||
| 38 | $group1 = new Group('One'); |
||
| 39 | $group2 = new Group('Two'); |
||
| 40 | |||
| 41 | $user = new User(); |
||
| 42 | $user->setId(self::$userId); |
||
|
0 ignored issues
–
show
The method
setId() does not seem to exist on object<Documents\User>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 43 | $user->setUsername('alcaeus'); |
||
| 44 | $user->setCreatedAt(new DateTimeImmutable()); |
||
|
0 ignored issues
–
show
The method
setCreatedAt() does not seem to exist on object<Documents\User>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 45 | $user->setAddress($address); |
||
| 46 | $user->setAccount($account); |
||
| 47 | $user->addPhonenumber(new Phonenumber('12345678')); |
||
| 48 | $user->addGroup($group1); |
||
|
0 ignored issues
–
show
The method
addGroup() does not seem to exist on object<Documents\User>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 49 | $user->addGroup($group2); |
||
|
0 ignored issues
–
show
The method
addGroup() does not seem to exist on object<Documents\User>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 50 | |||
| 51 | $this->getDocumentManager()->persist($user); |
||
| 52 | $this->getDocumentManager()->flush(); |
||
| 53 | |||
| 54 | $this->getDocumentManager()->clear(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @Warmup(2) |
||
| 59 | */ |
||
| 60 | public function benchLoadDocument() |
||
| 61 | { |
||
| 62 | $this->loadDocument(); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @Warmup(2) |
||
| 67 | */ |
||
| 68 | public function benchLoadEmbedOne() |
||
| 69 | { |
||
| 70 | $this->loadDocument()->getAddress()->getCity(); |
||
|
0 ignored issues
–
show
The call to the method
Documents\Address::getCity() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @Warmup(2) |
||
| 75 | */ |
||
| 76 | public function benchLoadEmbedMany() |
||
| 77 | { |
||
| 78 | $this->loadDocument()->getPhonenumbers()->forAll(static function ($key, Phonenumber $element) { |
||
| 79 | return $element->getPhoneNumber(); |
||
| 80 | }); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @Warmup(2) |
||
| 85 | */ |
||
| 86 | public function benchLoadReferenceOne() |
||
| 87 | { |
||
| 88 | $this->loadDocument()->getAccount()->getName(); |
||
|
0 ignored issues
–
show
The call to the method
Documents\Account::getName() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @Warmup(2) |
||
| 93 | */ |
||
| 94 | public function benchLoadReferenceMany() |
||
| 95 | { |
||
| 96 | $this->loadDocument()->getGroups()->forAll(static function ($key, Group $group) { |
||
|
0 ignored issues
–
show
The method
getGroups() does not seem to exist on object<Documents\User>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 97 | return $group->getName(); |
||
| 98 | }); |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return User |
||
| 103 | */ |
||
| 104 | private function loadDocument() |
||
| 105 | { |
||
| 106 | $document = $this->getDocumentManager()->find(User::class, self::$userId); |
||
| 107 | assert($document instanceof User); |
||
| 108 | |||
| 109 | return $document; |
||
| 110 | } |
||
| 111 | } |
||
| 112 |
This check looks for function calls that miss required arguments.