Passed
Push — master ( 818b3e...c1bcf5 )
by Thierry
02:23
created

UploadAnnotation::initAnnotation()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * UploadAnnotation.php
5
 *
6
 * Jaxon annotation for file upload.
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @copyright 2022 Thierry Feuzeu <[email protected]>
10
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
11
 * @link https://github.com/jaxon-php/jaxon-core
12
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
13
14
namespace Jaxon\Annotations\Annotation;
15
16
use mindplay\annotations\Annotation;
17
use mindplay\annotations\AnnotationException;
18
19
use function count;
20
use function is_string;
21
22
/**
23
 * Specifies an upload form field id.
24
 *
25
 * @usage('method'=>true)
26
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
27
class UploadAnnotation extends AbstractAnnotation
28
{
29
    /**
30
     * The name of the upload field
31
     *
32
     * @var string
33
     */
34
    protected $sField = '';
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $properties should have a doc-comment as per coding-style.
Loading history...
37
     * @inheritDoc
38
     * @throws AnnotationException
39
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
40
    public function initAnnotation(array $properties)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
41
    {
42
        if(count($properties) != 1 || !isset($properties['field']) || !is_string($properties['field']))
43
        {
44
            throw new AnnotationException('The @upload annotation requires a property "field" of type string');
45
        }
46
        $this->sField = $properties['field'];
47
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
    /**
50
     * @inheritDoc
51
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
52
    public function getName(): string
53
    {
54
        return 'upload';
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
56
57
    /**
58
     * @inheritDoc
59
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
60
    public function getValue()
61
    {
62
        return "'" . $this->sField . "'" ; // The field id is surrounded with simple quotes.
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
64
}
65