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

Timestamp::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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