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

WebhookExchangeRepository::findByUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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