Completed
Push — master ( 861886...cceff3 )
by John
10:56
created

Mautic::getCookie()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Escopecz\MauticFormSubmit;
4
5
use Escopecz\MauticFormSubmit\Mautic\Form;
6
use Escopecz\MauticFormSubmit\Mautic\Contact;
7
use Escopecz\MauticFormSubmit\Mautic\Cookie;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Escopecz\MauticFormSubmit\Cookie.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
9
/**
10
 * Mautic representation
11
 */
12
class Mautic
13
{
14
    /**
15
     * Mautic base (root) URL
16
     *
17
     * @var string
18
     */
19
    protected $baseUrl;
20
21
    /**
22
     * Mautic Contact
23
     *
24
     * @var Contact
25
     */
26
    protected $contact;
27
28
    /**
29
     * Mautic Contact Cookie
30
     *
31
     * @var Cookie
32
     */
33
    protected $cookie;
34
35
    /**
36
     * Constructor
37
     *
38
     * @param string $baseUrl
39
     */
40 26
    public function __construct($baseUrl)
41
    {
42 26
        $this->baseUrl = rtrim(trim($baseUrl), '/');
43 26
        $this->cookie = new Cookie;
44 26
        $this->contact = new Contact($this->cookie);
45 26
    }
46
47
    /**
48
     * Returns Mautic's base URL
49
     *
50
     * @return string
51
     */
52 6
    public function getBaseUrl()
53
    {
54 6
        return $this->baseUrl;
55
    }
56
57
    /**
58
     * Returns new Mautic Form representation object
59
     *
60
     * @param  int $id
61
     *
62
     * @return Form
63
     */
64 10
    public function getForm($id)
65
    {
66 10
        return new Form($this, $id);
67
    }
68
69
    /**
70
     * Sets the Mautic Contact if you want to replace the default one
71
     *
72
     * @param Contact $contact
73
     *
74
     * @return Mautic
75
     */
76 2
    public function setContact(Contact $contact)
77
    {
78 2
        $this->contact = $contact;
79
80 2
        return $this;
81
    }
82
83
    /**
84
     * Returns Mautic Contact representation object
85
     *
86
     * @return Contact
87
     */
88 12
    public function getContact()
89
    {
90 12
        return $this->contact;
91
    }
92
93
    /**
94
     * Returns Mautic Cookie representation object
95
     *
96
     * @return Cookie
97
     */
98
    public function getCookie()
99
    {
100
        return $this->cookie;
101
    }
102
}
103