DeleteFile::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 0
1
<?php
2
3
namespace Akeneo\Crowdin\Api;
4
5
use \InvalidArgumentException;
6
7
/**
8
 * Deletes a file from a Crowdin project. All the translations will be lost without ability to restore them.
9
 *
10
 * @author Julien Janvier <[email protected]>
11
 * @see https://crowdin.com/page/api/delete-file
12
 */
13 View Code Duplication
class DeleteFile extends AbstractApi
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /** @var string */
16
    protected $file;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function execute()
22
    {
23
        if (null == $this->file) {
24
            throw new InvalidArgumentException('There is no file to delete.');
25
        }
26
27
        $this->addUrlParameter('key', $this->client->getProjectApiKey());
28
        
29
        $path = sprintf(
30
            "project/%s/delete-file?%s",
31
            $this->client->getProjectIdentifier(),
32
            $this->getUrlQueryString()
33
        );
34
35
        $parameters = ['file' => $this->file];
36
37
        $data = ['form_params' => $parameters];
38
        $response = $this->client->getHttpClient()->post($path, $data);
39
40
        return $response->getBody();
41
    }
42
43
    /**
44
     * @param mixed $file
45
     *
46
     * @return DeleteFile
47
     */
48
    public function setFile($file)
49
    {
50
        $this->file = $file;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    public function getFile()
59
    {
60
        return $this->file;
61
    }
62
}
63