Profileable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProfileFactory() 0 3 1
A createProfile() 0 3 1
A getProfileFactory() 0 7 2
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Observability\Traits;
4
5
use RemotelyLiving\PHPDNS\Observability\Performance\Profile;
6
use RemotelyLiving\PHPDNS\Observability\Performance\ProfileFactory;
7
8
trait Profileable
9
{
10
    private ?ProfileFactory $profileFactory = null;
11
12
    public function createProfile(string $transactionName): Profile
13
    {
14
        return $this->getProfileFactory()->create($transactionName);
15
    }
16
17
    public function setProfileFactory(ProfileFactory $profileFactory): void
18
    {
19
        $this->profileFactory = $profileFactory;
20
    }
21
22
    private function getProfileFactory(): ProfileFactory
23
    {
24
        if ($this->profileFactory === null) {
25
            $this->profileFactory = new ProfileFactory();
26
        }
27
28
        return $this->profileFactory;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->profileFactory could return the type null which is incompatible with the type-hinted return RemotelyLiving\PHPDNS\Ob...formance\ProfileFactory. Consider adding an additional type-check to rule them out.
Loading history...
29
    }
30
}
31