Issues (124)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Query/ExecutionsProvider.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen\Query;
11
12
use Illuminate\Support\Arr;
13
use RDS\Hydrogen\Query;
14
use RDS\Hydrogen\Collection\Collection;
15
16
/**
17
 * Class ExecutionsProvider
18
 * @mixin Query
19
 */
20
trait ExecutionsProvider
21
{
22
    /**
23
     * @param string ...$fields
24
     * @return object[]|iterable
25
     */
26 20
    public function get(string ...$fields): iterable
27
    {
28 20
        $processor = $this->getRepository()->getProcessor();
0 ignored issues
show
It seems like getRepository() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
29
30 20
        return $processor->getResult($this, ...$fields);
31
    }
32
33
    /**
34
     * Get the values of a given key.
35
     *
36
     * @param string|array $value
37
     * @param string|null $key
38
     * @return Collection|iterable
39
     */
40
    public function pluck($value, $key = null): array
41
    {
42
        return $this
43
            ->collect(...\array_filter([$value, $key]))
44
            ->pluck($value, $key)
45
            ->toArray();
46
    }
47
48
    /**
49
     * @param string $field
50
     * @param string|null $typeOf
51
     * @return mixed
52
     * @throws \LogicException
53
     */
54 10
    public function scalar(string $field, string $typeOf = null)
55
    {
56 10
        $processor = $this->getRepository()->getProcessor();
0 ignored issues
show
It seems like getRepository() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
57
58 10
        $result = $processor->getScalarResult($this, $field);
59
60 10
        if ($typeOf !== null) {
61 10
            return $this->cast($result, $typeOf);
62
        }
63
64
        return $result;
65
    }
66
67
    /**
68
     * @param mixed $result
69
     * @param string $typeOf
70
     * @return array|\Closure|object|mixed
71
     */
72 10
    private function cast($result, string $typeOf)
73
    {
74 10
        $typeOf = \strtolower($typeOf);
75
76
        switch ($typeOf) {
77 10
            case 'callable':
78
                return function (callable $applicator = null) use ($result) {
79
                    return ($applicator ?? '\\value')($result);
80
                };
81
82 10
            case 'object':
83
                return (object)$result;
84
85 10
            case 'array':
86 10
            case 'iterable':
87
                return (array)$result;
88
89 10
            case 'string':
90
                return (string)$result;
91
        }
92
93 10
        $function = $typeOf . 'val';
94
95 10
        if (! \function_exists($function)) {
96
            throw new \InvalidArgumentException('Could not cast to type ' . $typeOf);
97
        }
98
99 10
        return $function($result);
100
    }
101
102
    /**
103
     * @param string|null $field
104
     * @return int
105
     * @throws \LogicException
106
     */
107 2
    public function count(string $field = null): int
108
    {
109 2
        if ($field === null) {
110
            $field = \array_first($this->getMetadata()->identifier);
0 ignored issues
show
It seems like getMetadata() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
111
        }
112
113
        return $this
0 ignored issues
show
It seems like select() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
114 2
            ->select('COUNT(' . $field . ') AS __count')
115 2
            ->scalar('__count', 'int');
116
    }
117
118
    /**
119
     * @param string|null $field
120
     * @return int
121
     * @throws \LogicException
122
     */
123 2
    public function sum(string $field = null): int
124
    {
125
        return $this
0 ignored issues
show
It seems like select() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
126 2
            ->select('SUM(' . $field . ') AS __sum')
127 2
            ->scalar('__sum', 'int');
128
    }
129
130
    /**
131
     * @param string|null $field
132
     * @return int
133
     * @throws \LogicException
134
     */
135 2
    public function avg(string $field = null): int
136
    {
137
        return $this
0 ignored issues
show
It seems like select() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
138 2
            ->select('AVG(' . $field . ') AS __avg')
139 2
            ->scalar('__avg', 'int');
140
    }
141
142
    /**
143
     * @param string|null $field
144
     * @return int
145
     * @throws \LogicException
146
     */
147 2
    public function max(string $field = null): int
148
    {
149
        return $this
0 ignored issues
show
It seems like select() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
150 2
            ->select('MAX(' . $field . ') AS __max')
151 2
            ->scalar('__max', 'int');
152
    }
153
154
    /**
155
     * @param string|null $field
156
     * @return int
157
     * @throws \LogicException
158
     */
159 2
    public function min(string $field = null): int
160
    {
161
        return $this
0 ignored issues
show
It seems like select() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
162 2
            ->select('MIN(' . $field . ') AS __min')
163 2
            ->scalar('__min', 'int');
164
    }
165
166
    /**
167
     * @param string ...$fields
168
     * @return Collection
169
     */
170 2
    public function collect(string ...$fields): Collection
171
    {
172 2
        return Collection::wrap($this->get(...$fields));
173
    }
174
175
    /**
176
     * @param string[] $fields
177
     * @return object|null
178
     * @throws \LogicException
179
     */
180
    public function first(string ...$fields)
181
    {
182
        return \array_first($this->get(...$fields));
183
    }
184
}
185