NewsletterService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerNew() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Newsletter\Service;
6
7
use Newsletter\Mapper\NewsletterMapper;
8
9
class NewsletterService
10
{
11
    private $newsletterMapper;
12
13
    public function __construct(NewsletterMapper $newsletterMapper)
14
    {
15
        $this->newsletterMapper = $newsletterMapper;
16
    }
17
18
    public function registerNew($email)
19
    {
20
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
21
            throw new \Exception('Email is not valid!', 400);
22
        }
23
24
        $current = $this->newsletterMapper->select(['email' => $email])->current();
25
26
        if (!$current) {
27
            return $this->newsletterMapper->insert(['email' => $email]);
28
        }
29
    }
30
}
31