Issues (27)

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/PropertyStore.php (2 issues)

Labels
Severity

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
namespace Queryr\EntityStore;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\DBALException;
7
use Queryr\EntityStore\Data\PropertyInfo;
8
use Queryr\EntityStore\Data\PropertyRow;
9
use Wikibase\DataModel\Entity\PropertyId;
10
11
/**
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class PropertyStore {
16
17
	private $connection;
18
	private $tableName;
19
20
	/**
21
	 * This constructor is package private. Construction is done via EntityStoreFactory.
22
	 *
23
	 * @param Connection $connection
24
	 * @param string $tableName
25
	 */
26 19
	public function __construct( Connection $connection, $tableName ) {
27 19
		$this->connection = $connection;
28 19
		$this->tableName = $tableName;
29 19
	}
30
31
	/**
32
	 * @param PropertyRow $propertyRow
33
	 *
34
	 * @throws EntityStoreException
35
	 */
36 7
	public function storePropertyRow( PropertyRow $propertyRow ) {
37 7
		$this->deletePropertyById( PropertyId::newFromNumber( $propertyRow->getNumericPropertyId() ) );
38
39
		try {
40 5
			$this->connection->insert(
41 5
				$this->tableName,
42
				array(
43 5
					'property_id' => $propertyRow->getNumericPropertyId(),
44 5
					'property_json' => $propertyRow->getPropertyJson(),
45
46 5
					'page_title' => $propertyRow->getPageTitle(),
47 5
					'revision_id' => $propertyRow->getRevisionId(),
48 5
					'revision_time' => $propertyRow->getRevisionTime(),
49
50 5
					'property_type' => $propertyRow->getPropertyType(),
51
				)
52
			);
53
		}
54
		catch ( DBALException $ex ) {
55
			throw new EntityStoreException( $ex->getMessage(), $ex );
56
		}
57 5
	}
58
59
	/**
60
	 * @param PropertyId $propertyId
61
	 *
62
	 * @throws EntityStoreException
63
	 */
64 8
	public function deletePropertyById( PropertyId $propertyId ) {
65
		try {
66 8
			$this->connection->delete(
67 8
				$this->tableName,
68
				[
69 8
					'property_id' => $propertyId->getNumericId()
70
				]
71
			);
72
		}
73 3
		catch ( DBALException $ex ) {
74 3
			throw new EntityStoreException( $ex->getMessage(), $ex );
75
		}
76 5
	}
77
78
	/**
79
	 * @param string|int $numericPropertyId
80
	 *
81
	 * @return PropertyRow|null
82
	 * @throws EntityStoreException
83
	 */
84 6
	public function getPropertyRowByNumericPropertyId( $numericPropertyId ) {
85
		try {
86 6
			$rows = $this->selectProperties()
87 6
				->where( 'property_id = ?' )
88 6
				->setParameter( 0, (int)$numericPropertyId )
89 6
				->execute();
90
		}
91 2
		catch ( DBALException $ex ) {
92 2
			throw new EntityStoreException( $ex->getMessage(), $ex );
93
		}
94
95 4
		return $this->newPropertyRowFromResult( $rows );
0 ignored issues
show
It seems like $rows defined by $this->selectProperties(...cPropertyId)->execute() on line 86 can also be of type integer; however, Queryr\EntityStore\Prope...PropertyRowFromResult() does only seem to accept object<Traversable>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
96
	}
97
98 6
	private function selectProperties() {
99 6
		return $this->connection->createQueryBuilder()->select(
100 6
			'property_id',
101 6
			'property_json',
102 6
			'page_title',
103 6
			'revision_id',
104 6
			'revision_time',
105 6
			'property_type'
106 6
		)->from( $this->tableName );
107
	}
108
109 4
	private function newPropertyRowFromResult( \Traversable $rows ) {
110 4
		$rows = iterator_to_array( $rows );
111
112 4
		if ( count( $rows ) < 1 ) {
113 2
			return null;
114
		}
115
116 2
		$row = reset( $rows );
117
118 2
		return new PropertyRow(
119 2
			$row['property_json'],
120 2
			$this->newPropertyInfoFromResultRow( $row )
121
		);
122
	}
123
124 4
	private function newPropertyInfoFromResultRow( array $row ) {
125 4
		return new PropertyInfo(
126 4
			$row['property_id'],
127 4
			$row['page_title'],
128 4
			$row['revision_id'],
129 4
			$row['revision_time'],
130 4
			$row['property_type']
131
		);
132
	}
133
134 5
	private function selectPropertyInfoSets() {
135 5
		return $this->connection->createQueryBuilder()->select(
136 5
			'property_id',
137 5
			'page_title',
138 5
			'revision_id',
139 5
			'revision_time',
140 5
			'property_type'
141 5
		)->from( $this->tableName );
142
	}
143
144
	/**
145
	 * @param int $limit
146
	 * @param int $offset
147
	 *
148
	 * @return PropertyInfo[]
149
	 * @throws EntityStoreException
150
	 */
151 5
	public function getPropertyInfo( $limit, $offset ) {
152
		try {
153 5
			$rows = $this->selectPropertyInfoSets()
154 5
				->orderBy( 'property_id', 'asc' )
155 5
				->setMaxResults( $limit )
156 5
				->setFirstResult( $offset )
157 5
				->execute();
158
		}
159 2
		catch ( DBALException $ex ) {
160 2
			throw new EntityStoreException( $ex->getMessage(), $ex );
161
		}
162
163 3
		return $this->newPropertyInfoArrayFromResult( $rows );
0 ignored issues
show
It seems like $rows defined by $this->selectPropertyInf...ult($offset)->execute() on line 153 can also be of type integer; however, Queryr\EntityStore\Prope...tyInfoArrayFromResult() does only seem to accept object<Traversable>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
164
	}
165
166 3
	private function newPropertyInfoArrayFromResult( \Traversable $rows ) {
167 3
		$infoList = [];
168
169 3
		foreach ( $rows as $resultRow ) {
170 2
			$infoList[] = $this->newPropertyInfoFromResultRow( $resultRow );
171
		}
172
173 3
		return $infoList;
174
	}
175
176
}