Passed
Push — main ( e8aeda...1a1ce5 )
by Dimitri
14:44 queued 09:57
created

ResourceController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Controllers;
13
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * Un contrôleur extensible pour fournir une API RESTful pour une ressource.
18
 */
19
class ResourceController extends RestController
20
{
21
	protected string $returnFormat = '';
22
23
	/**
24
	 * {@inheritDoc}
25
	 */
26
    public function __construct()
27
    {
28
        parent::__construct();
29
        $this->setFormat($this->returnFormat);
30
    }
31
32
    /**
33
     * Renvoie un tableau d'objets ressources, eux-mêmes au format tableau
34
     *
35
     * @return ResponseInterface|string|void
36
     */
37
    public function index()
38
    {
39
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
40
    }
41
42
    /**
43
     * Renvoyer les propriétés d'un objet ressource
44
     *
45
     * @param int|string|null $id
46
     *
47
     * @return ResponseInterface|string|void
48
     */
49
    public function show($id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    public function show(/** @scrutinizer ignore-unused */ $id = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
52
    }
53
54
    /**
55
     * Renvoie un nouvel objet ressource, avec les propriétés par défaut
56
     *
57
     * @return ResponseInterface|string|void
58
     */
59
    public function new()
60
    {
61
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
62
    }
63
64
    /**
65
     * Créer un nouvel objet ressource, à partir des données envoyées
66
     *
67
     * @return ResponseInterface|string|void
68
     */
69
    public function create()
70
    {
71
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
72
    }
73
74
    /**
75
     * Renvoyer les propriétés modifiables d'un objet ressource
76
     *
77
     * @param int|string|null $id
78
     *
79
     * @return ResponseInterface|string|void
80
     */
81
    public function edit($id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

81
    public function edit(/** @scrutinizer ignore-unused */ $id = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
84
    }
85
86
    /**
87
     * Ajouter ou mettre à jour une ressource de modèle, à partir de données envoyées
88
     *
89
     * @param int|string|null $id
90
     *
91
     * @return ResponseInterface|string|void
92
     */
93
    public function update($id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

93
    public function update(/** @scrutinizer ignore-unused */ $id = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
96
    }
97
98
    /**
99
     * Supprimer l'objet ressource désigné du modèle
100
     *
101
     * @param int|string|null $id
102
     *
103
     * @return ResponseInterface|string|void
104
     */
105
    public function delete($id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

105
    public function delete(/** @scrutinizer ignore-unused */ $id = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
    {
107
        return $this->respondNotImplemented($this->_translate('notImplemented', [__METHOD__]));
108
    }
109
110
    /**
111
     * Définir/modifier la représentation de réponse attendue pour les objets renvoyés
112
     *
113
     * @param string $format json/xml
114
     *
115
     * @return void
116
     */
117
    public function setFormat(string $format = 'json')
118
    {
119
        if (in_array($format, ['json', 'xml'], true)) {
120
            $this->returnFormat($format);
121
        }
122
    }
123
}
124