1 | <?php |
||||||
2 | |||||||
3 | namespace Cog\Laravel\Optimus\Traits; |
||||||
4 | |||||||
5 | trait OptimusEncodedRouteKey |
||||||
6 | { |
||||||
7 | /** |
||||||
8 | * Get the value of the model's route key. |
||||||
9 | * |
||||||
10 | * @return mixed |
||||||
11 | */ |
||||||
12 | public function getRouteKey() |
||||||
13 | { |
||||||
14 | $id = parent::getRouteKey(); |
||||||
15 | |||||||
16 | return $this->getOptimus()->encode($id); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
17 | } |
||||||
18 | |||||||
19 | /** |
||||||
20 | * Retrieve the model for a bound value. |
||||||
21 | * |
||||||
22 | * @param mixed $value |
||||||
23 | * @param string|null $field |
||||||
24 | * @return \Illuminate\Database\Eloquent\Model|null |
||||||
25 | */ |
||||||
26 | public function resolveRouteBinding($value, $field = null) |
||||||
27 | { |
||||||
28 | if ($field === null) { |
||||||
29 | $field = $this->getRouteKeyName(); |
||||||
0 ignored issues
–
show
The method
getRouteKeyName() does not exist on Cog\Laravel\Optimus\Traits\OptimusEncodedRouteKey . Did you maybe mean getRouteKey() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
30 | } |
||||||
31 | |||||||
32 | if (is_string($value) && ctype_digit($value)) { |
||||||
33 | $value = (int) $value; |
||||||
34 | } |
||||||
35 | |||||||
36 | if (is_int($value) && $field === $this->getRouteKeyName()) { |
||||||
37 | $value = $this->getOptimus()->decode($value); |
||||||
0 ignored issues
–
show
The method
decode() does not exist on Cog\Laravel\Optimus\OptimusManager . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
38 | } |
||||||
39 | |||||||
40 | return $this->where($field, $value)->first(); |
||||||
0 ignored issues
–
show
It seems like
where() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
41 | } |
||||||
42 | |||||||
43 | /** |
||||||
44 | * Retrieve the model for a bound value. |
||||||
45 | * |
||||||
46 | * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation $query |
||||||
47 | * @param mixed $value |
||||||
48 | * @param string|null $field |
||||||
49 | * @return \Illuminate\Database\Eloquent\Relations\Relation |
||||||
50 | */ |
||||||
51 | public function resolveRouteBindingQuery($query, $value, $field = null) |
||||||
52 | { |
||||||
53 | if ($field === null) { |
||||||
54 | $field = $query->getRouteKeyName(); |
||||||
55 | } |
||||||
56 | |||||||
57 | if (is_string($value) && ctype_digit($value)) { |
||||||
58 | $value = (int) $value; |
||||||
59 | } |
||||||
60 | |||||||
61 | if (is_int($value) && $field === $this->getRouteKeyName()) { |
||||||
62 | $value = $this->getOptimus()->decode($value); |
||||||
63 | } |
||||||
64 | |||||||
65 | return $query->where($field, $value); |
||||||
0 ignored issues
–
show
|
|||||||
66 | } |
||||||
67 | |||||||
68 | /** |
||||||
69 | * Get the Optimus instance. |
||||||
70 | * |
||||||
71 | * @return \Cog\Laravel\Optimus\OptimusManager |
||||||
72 | */ |
||||||
73 | protected function getOptimus() |
||||||
74 | { |
||||||
75 | $connection = null; |
||||||
76 | |||||||
77 | if (property_exists($this, 'optimusConnection')) { |
||||||
78 | $connection = $this->optimusConnection; |
||||||
79 | } |
||||||
80 | |||||||
81 | return app('optimus')->connection($connection); |
||||||
82 | } |
||||||
83 | } |
||||||
84 |