These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace LaravelFeature\Repository; |
||
4 | |||
5 | use LaravelFeature\Domain\Exception\FeatureException; |
||
6 | use LaravelFeature\Domain\Repository\FeatureRepositoryInterface; |
||
7 | use LaravelFeature\Domain\Model\Feature; |
||
8 | use LaravelFeature\Featurable\FeaturableInterface; |
||
9 | use LaravelFeature\Model\Feature as Model; |
||
10 | |||
11 | class EloquentFeatureRepository implements FeatureRepositoryInterface |
||
12 | { |
||
13 | 9 | public function save(Feature $feature) |
|
14 | 9 | { |
|
15 | /** @var Model $model */ |
||
16 | 6 | $model = Model::where('name', '=', $feature->getName())->first(); |
|
17 | |||
18 | 6 | if (!$model) { |
|
19 | 6 | $model = new Model(); |
|
20 | 6 | } |
|
21 | |||
22 | 6 | $model->name = $feature->getName(); |
|
0 ignored issues
–
show
|
|||
23 | 6 | $model->is_enabled = $feature->isEnabled(); |
|
0 ignored issues
–
show
The property
is_enabled does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
24 | |||
25 | try { |
||
26 | 6 | $model->save(); |
|
27 | 6 | } catch (\Exception $e) { |
|
28 | 3 | throw new FeatureException('Unable to save the feature: ' . $e->getMessage()); |
|
29 | } |
||
30 | 3 | } |
|
31 | |||
32 | 6 | public function remove(Feature $feature) |
|
33 | { |
||
34 | /** @var Model $model */ |
||
35 | 6 | $model = Model::where('name', '=', $feature->getName())->first(); |
|
36 | 6 | if (!$model) { |
|
37 | 3 | throw new FeatureException('Unable to find the feature.'); |
|
38 | } |
||
39 | |||
40 | 3 | $model->delete(); |
|
41 | 3 | } |
|
42 | |||
43 | 6 | View Code Duplication | public function findByName($featureName) |
44 | { |
||
45 | /** @var Model $model */ |
||
46 | 6 | $model = Model::where('name', '=', $featureName)->first(); |
|
47 | 6 | if (!$model) { |
|
48 | 3 | throw new FeatureException('Unable to find the feature.'); |
|
49 | } |
||
50 | |||
51 | 3 | return Feature::fromNameAndStatus( |
|
52 | 3 | $model->name, |
|
0 ignored issues
–
show
The property
name does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
53 | 3 | $model->is_enabled |
|
0 ignored issues
–
show
The property
is_enabled does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
54 | 3 | ); |
|
55 | } |
||
56 | |||
57 | 9 | View Code Duplication | public function enableFor($featureName, FeaturableInterface $featurable) |
58 | { |
||
59 | /** @var Model $model */ |
||
60 | 9 | $model = Model::where('name', '=', $featureName)->first(); |
|
61 | 9 | if (!$model) { |
|
62 | 3 | throw new FeatureException('Unable to find the feature.'); |
|
63 | } |
||
64 | |||
65 | 6 | if ((bool) $model->is_enabled === true || $featurable->hasFeature($featureName) === true) { |
|
0 ignored issues
–
show
The property
is_enabled does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
66 | 3 | return; |
|
67 | } |
||
68 | |||
69 | 3 | $featurable->features()->attach($model->id); |
|
0 ignored issues
–
show
The property
id does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
70 | 3 | } |
|
71 | |||
72 | 9 | View Code Duplication | public function disableFor($featureName, FeaturableInterface $featurable) |
73 | { |
||
74 | /** @var Model $model */ |
||
75 | 9 | $model = Model::where('name', '=', $featureName)->first(); |
|
76 | 9 | if (!$model) { |
|
77 | 3 | throw new FeatureException('Unable to find the feature.'); |
|
78 | } |
||
79 | |||
80 | 6 | if ((bool) $model->is_enabled === true || $featurable->hasFeature($featureName) === false) { |
|
0 ignored issues
–
show
The property
is_enabled does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
81 | 3 | return; |
|
82 | } |
||
83 | |||
84 | 3 | $featurable->features()->detach($model->id); |
|
0 ignored issues
–
show
The property
id does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
85 | 3 | } |
|
86 | |||
87 | 6 | View Code Duplication | public function isEnabledFor($featureName, FeaturableInterface $featurable) |
88 | { |
||
89 | /** @var Model $model */ |
||
90 | 6 | $model = Model::where('name', '=', $featureName)->first(); |
|
91 | 6 | if (!$model) { |
|
92 | 3 | throw new FeatureException('Unable to find the feature.'); |
|
93 | } |
||
94 | |||
95 | 3 | return ($model->is_enabled) ? true : $featurable->hasFeature($featureName); |
|
0 ignored issues
–
show
The property
is_enabled does not exist on object<LaravelFeature\Model\Feature> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
96 | } |
||
97 | } |
||
98 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.