Completed
Pull Request — master (#121)
by Kristof
04:38
created

OfferEditingTrait::removeImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/**
4
 * @file
5
 * Contains CultuurNet\UDB3\OfferEditingTrait.
6
 */
7
8
namespace CultuurNet\UDB3;
9
10
use CultuurNet\UDB3\Media\Image;
11
use CultuurNet\UDB3\Media\MediaObject;
12
use ValueObjects\String\String;
13
14
/**
15
 * Trait that contains all major editing methods for Offers.
16
 */
17
trait OfferEditingTrait
18
{
19
20
    /**
21
     * Get the namespaced classname of the command to create.
22
     * @param type $className
23
     *   Name of the class
24
     * @return string
25
     */
26
    private function getCommandClass($className)
27
    {
28
        $reflection = new \ReflectionObject($this);
29
        return $reflection->getNamespaceName() . '\\Commands\\' . $className;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 View Code Duplication
    public function updateDescription($id, $description)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
38
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
40
        $commandClass = $this->getCommandClass('UpdateDescription');
0 ignored issues
show
Documentation introduced by
'UpdateDescription' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
42
        return $this->commandBus->dispatch(
0 ignored issues
show
Bug introduced by
The property commandBus does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
            new $commandClass($id, $description)
44
        );
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 View Code Duplication
    public function updateTypicalAgeRange($id, $ageRange)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
53
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
54
55
        $commandClass = $this->getCommandClass('UpdateTypicalAgeRange');
0 ignored issues
show
Documentation introduced by
'UpdateTypicalAgeRange' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
57
        return $this->commandBus->dispatch(
58
            new $commandClass($id, $ageRange)
59
        );
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function deleteTypicalAgeRange($id)
66
    {
67
68
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
70
        $commandClass = $this->getCommandClass('DeleteTypicalAgeRange');
0 ignored issues
show
Documentation introduced by
'DeleteTypicalAgeRange' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
72
        return $this->commandBus->dispatch(
73
            new $commandClass($id)
74
        );
75
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 View Code Duplication
    public function updateOrganizer($id, $organizerId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
84
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
85
86
        $commandClass = $this->getCommandClass('UpdateOrganizer');
0 ignored issues
show
Documentation introduced by
'UpdateOrganizer' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
88
        return $this->commandBus->dispatch(
89
            new $commandClass($id, $organizerId)
90
        );
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96 View Code Duplication
    public function deleteOrganizer($id, $organizerId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
99
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
100
101
        $commandClass = $this->getCommandClass('DeleteOrganizer');
0 ignored issues
show
Documentation introduced by
'DeleteOrganizer' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
103
        return $this->commandBus->dispatch(
104
            new $commandClass($id, $organizerId)
105
        );
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 View Code Duplication
    public function updateContactPoint($id, ContactPoint $contactPoint)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
114
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
115
116
        $commandClass = $this->getCommandClass('UpdateContactPoint');
0 ignored issues
show
Documentation introduced by
'UpdateContactPoint' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117
118
        return $this->commandBus->dispatch(
119
            new $commandClass($id, $contactPoint)
120
        );
121
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127 View Code Duplication
    public function updateBookingInfo($id, BookingInfo $bookingInfo)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
130
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
131
132
        $commandClass = $this->getCommandClass('UpdateBookingInfo');
0 ignored issues
show
Documentation introduced by
'UpdateBookingInfo' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
133
134
        return $this->commandBus->dispatch(
135
            new $commandClass($id, $bookingInfo)
136
        );
137
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143 View Code Duplication
    public function addImage($id, Image $image)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
    {
145
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
146
147
        $commandClass = $this->getCommandClass('AddImage');
0 ignored issues
show
Documentation introduced by
'AddImage' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
148
149
        return $this->commandBus->dispatch(
150
            new $commandClass($id, $image)
151
        );
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157 View Code Duplication
    public function updateImage(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
        $id,
159
        Image $image,
160
        String $description,
161
        String $copyrightHolder
162
    ) {
163
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
164
165
        $commandClass = $this->getCommandClass('UpdateImage');
0 ignored issues
show
Documentation introduced by
'UpdateImage' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
167
        return $this->commandBus->dispatch(
168
            new $commandClass(
169
                $id,
170
                $image->getMediaObjectId(),
171
                $description,
172
                $copyrightHolder
173
            )
174
        );
175
    }
176
177
    /**
178
     * @param $id
179
     *  Id of the offer to remove the image from.
180
     *
181
     * @param Image $image
182
     *  The image that should be removed.
183
     *
184
     * @return mixed
185
     */
186
    public function removeImage($id, Image $image)
187
    {
188
        $this->guardId($id);
0 ignored issues
show
Bug introduced by
It seems like guardId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
189
190
        $commandClass = $this->getCommandClass('RemoveImage');
0 ignored issues
show
Documentation introduced by
'RemoveImage' is of type string, but the function expects a object<CultuurNet\UDB3\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
191
192
        return $this->commandBus->dispatch(
193
            new $commandClass($id, $image)
194
        );
195
196
    }
197
}
198