Issues (86)

Security Analysis    not enabled

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Trucker/Finders/CollectionFinder.php (4 issues)

Labels
Severity
1
<?php
2
3
namespace Trucker\Finders;
4
5
use Illuminate\Container\Container;
6
use Trucker\Facades\AuthFactory;
7
use Trucker\Facades\Config;
8
use Trucker\Facades\RequestFactory;
9
use Trucker\Facades\UrlGenerator;
10
use Trucker\Finders\Conditions\QueryConditionInterface;
11
use Trucker\Finders\Conditions\QueryResultOrderInterface;
12
use Trucker\Resource\Model;
13
use Trucker\Responses\Collection;
14
15
/**
16
 * Class for finding collections of models over the remote API.
17
 *
18
 * @author Alessandro Manno <[email protected]>
19
 */
20
class CollectionFinder
21
{
22
    /**
23
     * The IoC Container.
24
     *
25
     * @var Container
26
     */
27
    protected $app;
28
29
    /**
30
     * Build a new CollectionFinder.
31
     *
32
     * @param Container $app
33
     */
34 1
    public function __construct(Container $app)
35
    {
36 1
        $this->app = $app;
37 1
    }
38
39
    /**
40
     * Function to fetch a collection of Trucker\Resource\Model object
41
     * from the remote API.
42
     *
43
     * @param Model                     $model       Instance of entity type being fetched
44
     * @param QueryConditionInterface   $condition   Query conditions for the request
45
     * @param QueryResultOrderInterface $resultOrder Result ordering requirements for the request
46
     * @param array                     $getParams   Additional GET parameters to send w/ request
47
     *
48
     * @return Collection
49
     */
50 4
    public function fetch(
51
        Model $model,
52
        QueryConditionInterface $condition = null,
53
        QueryResultOrderInterface $resultOrder = null,
54
        array $getParams = []
55
    ) {
56
        //get a request object
57 4
        $request = RequestFactory::build();
0 ignored issues
show
The method build() does not exist on Trucker\Facades\RequestFactory. Since you implemented __callStatic, 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 ignore-call  annotation

57
        /** @scrutinizer ignore-call */ 
58
        $request = RequestFactory::build();
Loading history...
58
59
        //init the request
60 4
        $request->createRequest(
61 4
            Config::get('request.base_uri'),
0 ignored issues
show
The method get() does not exist on Trucker\Facades\Config. Since you implemented __callStatic, 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 ignore-call  annotation

61
            Config::/** @scrutinizer ignore-call */ 
62
                    get('request.base_uri'),
Loading history...
62 4
            UrlGenerator::getCollectionUri($model),
0 ignored issues
show
The method getCollectionUri() does not exist on Trucker\Facades\UrlGenerator. Since you implemented __callStatic, 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 ignore-call  annotation

62
            UrlGenerator::/** @scrutinizer ignore-call */ 
63
                          getCollectionUri($model),
Loading history...
63 4
            'GET'
64
        );
65
66
        //add auth if it is needed
67 4
        if ($auth = AuthFactory::build()) {
0 ignored issues
show
The method build() does not exist on Trucker\Facades\AuthFactory. Since you implemented __callStatic, 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 ignore-call  annotation

67
        if ($auth = AuthFactory::/** @scrutinizer ignore-call */ build()) {
Loading history...
68
            $request->authenticate($auth);
69
        }
70
71
        //add query conditions if needed
72 4
        if ($condition) {
73 1
            $request->addQueryCondition($condition);
74
        }
75
76
        //add result ordering if needed
77 4
        if ($resultOrder) {
78 1
            $request->addQueryResultOrder($resultOrder);
79
        }
80
81
        //set any get parameters on the request
82 4
        $request->setGetParameters($getParams);
83
84
        //actually send the request
85 4
        $response = $request->sendRequest();
86
87
        //get api response
88 4
        $data = $response->parseResponseToData();
89
90
        //make an array to hold results
91 4
        $records = [];
92
93
        //figure out wether a collection key is used
94 4
        $collection_key = Config::get('resource.collection_key');
95
96
        //set records array appropriatley
97 4
        $recordCollection = $data;
98
99 4
        if (isset($collection_key)) {
100 1
            $recordCollection = $data[$collection_key];
101
        }
102
103
        //create an array of popuplated results
104 4
        foreach ($recordCollection as $values) {
105 4
            $instance = new $model($values);
106
107
            //inflate the ID property that should be guarded
108 4
            $id = $instance->getIdentityProperty();
109 4
            if (array_key_exists($id, $values)) {
110 4
                $instance->{$id} = $values[$id];
111
            }
112
113
            //add the instance to the records array
114 4
            $records[] = $instance;
115
        }//end foreach
116
117
        //create a collection object to return
118 4
        $collection = new Collection($records);
119
120
        // if there was a collection_key, put any extra data that was returned
121
        // outside the collection key in the metaData attribute
122 4
        if (isset($collection_key)) {
123 1
            $collection->metaData = array_diff_key($data, array_flip([$collection_key]));
124
        }
125
126 4
        return $collection;
127
    }
128
}
129