Completed
Push — master ( b123ad...2604a0 )
by Joachim
02:07
created

WebhookExchangeRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findByUrlOrCreate() 0 14 2
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
class WebhookExchangeRepository extends EntityRepository
6
{
7
    /**
8
     * This method will find the webhook exchange with the given URL
9
     * If it doesn't exist it will create it.
10
     *
11
     * @param string $url
12
     *
13
     * @return WebhookExchange
14
     */
15
    public function findByUrlOrCreate(string $url): WebhookExchange
16
    {
17
        /** @var WebhookExchange $obj */
18
        $obj = $this->findOneBy([
19
            'url' => $url,
20
        ]);
21
22
        if (!$obj) {
23
            $obj = new WebhookExchange($url);
24
            $this->save($obj);
25
        }
26
27
        return $obj;
28
    }
29
}
30