Completed
Push — develop ( 087887...a1a657 )
by Žilvinas
07:31
created

Timestamp   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 7
dl 86
loc 86
ccs 26
cts 26
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getAction() 4 4 1
A getFields() 7 7 1
A createResult() 4 4 1
A getValidationConstraints() 22 22 1
A getMethod() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Isign\Document;
3
4
use Isign\DocumentTypeProvider;
5
use Isign\FileFieldsTrait;
6
use Isign\QueryInterface;
7
use Isign\ResultInterface;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
/**
11
 * Class Timestamp
12
 * Timestamps document's signatures.
13
 *
14
 * @package Isign\Document
15
 */
16 View Code Duplication
class Timestamp implements QueryInterface
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...
17
{
18
    use FileFieldsTrait;
19
20
    /** @var string Possible values: pdf, adoc, mdoc */
21
    private $type;
22
23
    /** @var string file path */
24
    private $path;
25
26
    /**
27
     * @param string $type Possible values: pdf, adoc, mdoc
28
     * @param string $path
29
     */
30 6
    public function __construct($type, $path)
31
    {
32 6
        $this->type = $type;
33 6
        $this->path = $path;
34 6
    }
35
36
    /**
37
     * API action name, part of full API request url
38
     * @return string
39
     */
40 1
    public function getAction()
41
    {
42 1
        return 'timestamp';
43
    }
44
45
    /**
46
     * Field and values association used in query
47
     * @return array
48
     */
49 2
    public function getFields()
50
    {
51
        return [
52 2
            'type' => $this->type,
53 2
            'file' => $this->getFileFields($this->path),
54
        ];
55
    }
56
57
    /**
58
     * Result object for this query result
59
     * @return ResultInterface
60
     */
61 1
    public function createResult()
62
    {
63 1
        return new TimestampResult();
64
    }
65
66
    /**
67
     * Validation constraints for fields
68
     * @return array
69
     */
70 1
    public function getValidationConstraints()
71
    {
72 1
        return new Assert\Collection([
73 1
            'type'  => new Assert\Required([
74 1
                new Assert\NotBlank(),
75 1
                new Assert\Choice([
76 1
                    'choices' => DocumentTypeProvider::getPrimaryDocumentTypes()
77
                ])
78
            ]),
79 1
            'file' => new Assert\Collection([
80 1
                'name' => new Assert\Required([
81 1
                    new Assert\NotBlank()
82
                ]),
83 1
                'content' => new Assert\Required([
84 1
                    new Assert\NotBlank(),
85
                ]),
86 1
                'digest' => new Assert\Required([
87 1
                    new Assert\NotBlank()
88
                ]),
89
            ]),
90
        ]);
91
    }
92
93
    /**
94
     * HTTP method to use
95
     * @return string
96
     */
97 1
    public function getMethod()
98
    {
99 1
        return QueryInterface::POST;
100
    }
101
}
102