Issues (461)

Branch: master

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.

includes/classes/class-lsx-schema-graph-piece.php (25 issues)

1
<?php
2
/**
3
 * Schema for LSX
4
 *
5
 * @package lsx
6
 */
0 ignored issues
show
There must be exactly one blank line after the file comment
Loading history...
7
/**
8
 * Returns schema Review data.
9
 *
10
 * @since 10.2
11
 */
12
use \Yoast\WP\SEO\Generators\Schema\Abstract_Schema_Piece;
0 ignored issues
show
The type \Yoast\WP\SEO\Generators...a\Abstract_Schema_Piece was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
if ( class_exists( 'Abstract_Schema_Piece' ) ) {
15
	class LSX_Schema_Graph_Piece extends Abstract_Schema_Piece {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class LSX_Schema_Graph_Piece
Loading history...
16
		/**
17
		 * A value object with context variables.
18
		 *
19
		 * @var \WPSEO_Schema_Context
20
		 */
21
		public $context;
22
		/**
23
		 * This is the post type that you want the piece to output for.
24
		 *
25
		 * @var string;
26
		 */
27
		public $post_type;
28
		/**
29
		 * If this is a top level parent
30
		 *
31
		 * @var boolean
32
		 */
33
		public $is_top_level;
34
		/**
35
		 * This holds the meta_key => scehma_type of the fields you want to add to your subtrip.
36
		 *
37
		 * @var array()
38
		 */
39
		public $place_ids;
40
		/**
41
		 * This holds an object or the current trip post.
42
		 *
43
		 * @var WP_Post();
44
		 */
45
		public $post;
46
		/**
47
		 * This holds URL for the trip
48
		 *
49
		 * @var string
50
		 */
51
		public $post_url;
52
		/**
53
		 * Constructor.
54
		 *
55
		 * @param \WPSEO_Schema_Context $context A value object with context variables.
56
		 */
57
		public function __construct( WPSEO_Schema_Context $context ) {
58
			$this->context      = $context;
59
			$this->place_ids    = array();
60
			$this->post         = get_post( $this->context->id );
0 ignored issues
show
$this->context->id of type string is incompatible with the type WP_Post|integer|null expected by parameter $post of get_post(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
			$this->post         = get_post( /** @scrutinizer ignore-type */ $this->context->id );
Loading history...
61
			$this->post_url     = get_permalink( $this->context->id );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_permalink($this->context->id) can also be of type false. However, the property $post_url is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
$this->context->id of type string is incompatible with the type WP_Post|integer expected by parameter $post of get_permalink(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
			$this->post_url     = get_permalink( /** @scrutinizer ignore-type */ $this->context->id );
Loading history...
62
			$this->is_top_level = false;
63
			if ( is_object( $this->post ) && isset( $this->post->post_parent ) && ( false === $this->post->post_parent || 0 === $this->post->post_parent || '' === $this->post->post_parent ) ) {
64
				$this->is_top_level = true;
65
			}
66
		}
67
		/**
68
		 * Determines whether or not a piece should be added to the graph.
69
		 *
70
		 * @return bool
71
		 */
72
		public function is_needed() {
73
			if ( ! is_singular() ) {
74
				return false;
75
			}
76
			if ( false === $this->context->site_represents ) {
0 ignored issues
show
The condition false === $this->context->site_represents is always false.
Loading history...
77
				return false;
78
			}
79
			return LSX_Schema_Utils::is_type( get_post_type(), $this->post_type );
80
		}
81
		/**
82
		 * Returns Review data.
83
		 *
84
		 * @return array $data Review data.
85
		 */
86
		public function generate() {
87
			$data = array();
88
			return $data;
89
		}
90
		/**
91
		 * Gets the connected reviews post type and set it as the "Review" schema
92
		 *
93
		 * @param  array    $data An array of offers already added.
0 ignored issues
show
Expected 3 spaces after parameter type; 4 found
Loading history...
94
		 * @param  string   $data_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 3 found
Loading history...
95
		 * @param  boolean  $include_aggregate
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 1 spaces after parameter type; 2 found
Loading history...
96
		 * @return array    $data
97
		 */
98
		public function add_reviews( $data, $data_key = 'reviews', $include_aggregate = true ) {
99
			$reviews       = get_post_meta( $this->context->id, 'review_to_' . $this->post_type, false );
0 ignored issues
show
$this->context->id of type string is incompatible with the type integer expected by parameter $post_id of get_post_meta(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

99
			$reviews       = get_post_meta( /** @scrutinizer ignore-type */ $this->context->id, 'review_to_' . $this->post_type, false );
Loading history...
100
			$reviews_array = array();
101
			if ( ! empty( $reviews ) ) {
102
				$aggregate_value = 1;
103
				$review_count    = 0;
104
				foreach ( $reviews as $review_id ) {
105
					$rating      = get_post_meta( $review_id, 'rating', true );
106
					$author      = get_post_meta( $review_id, 'reviewer_name', true );
107
					$description = wp_strip_all_tags( get_the_excerpt( $review_id ) );
108
					$review_args = array(
109
						'author'     => $author,
110
						'reviewBody' => $description,
111
					);
112
					// Add in the review rating.
113
					if ( false !== $rating && '' !== $rating && '0' !== $rating && 0 !== $rating ) {
114
						$review_args['reviewRating'] = array(
115
							'@type'       => 'Rating',
116
							'ratingValue' => $rating,
117
						);
118
					}
119
					$reviews_array = LSX_Schema_Utils::add_review( $reviews_array, $review_id, $this->context, $review_args );
0 ignored issues
show
The method add_review() does not exist on LSX_Schema_Utils. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
					/** @scrutinizer ignore-call */ 
120
     $reviews_array = LSX_Schema_Utils::add_review( $reviews_array, $review_id, $this->context, $review_args );

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.

Loading history...
120
					$review_count++;
121
				}
122
				if ( ! empty( $reviews_array ) ) {
123
					if ( true === $include_aggregate ) {
124
						$data['aggregateRating'] = array(
125
							'@type'       => 'AggregateRating',
126
							'ratingValue' => (string) $aggregate_value,
127
							'reviewCount' => (string) $review_count,
128
							'bestRating'  => '5',
129
							'worstRating' => '1',
130
						);
131
					}
132
					$data[ $data_key ] = $reviews_array;
133
				}
134
			}
135
			return $data;
136
		}
137
		/**
138
		 * Gets the connected posts and set it as the "Article" schema
139
		 *
140
		 * @param  array  $data An array of offers already added.
141
		 * @param  string $data_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
142
		 * @return array  $data
143
		 */
144
		public function add_articles( $data, $data_key = 'subjectOf' ) {
145
			$posts       = get_post_meta( $this->context->id, 'post_to_' . $this->post_type, false );
0 ignored issues
show
$this->context->id of type string is incompatible with the type integer expected by parameter $post_id of get_post_meta(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
			$posts       = get_post_meta( /** @scrutinizer ignore-type */ $this->context->id, 'post_to_' . $this->post_type, false );
Loading history...
146
			$posts_array = array();
147
			if ( ! empty( $posts ) ) {
148
				foreach ( $posts as $post_id ) {
149
					$post_args = array(
150
						'articleBody' => wp_strip_all_tags( get_the_excerpt( $post_id ) ),
151
						'headline'    => get_the_title( $post_id ),
152
					);
153
					$section   = get_the_term_list( $post_id, 'category' );
154
					if ( ! is_wp_error( $section ) && '' !== $section && false !== $section ) {
155
						$post_args['articleSection'] = wp_strip_all_tags( $section );
0 ignored issues
show
It seems like $section can also be of type WP_Error; however, parameter $text of wp_strip_all_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

155
						$post_args['articleSection'] = wp_strip_all_tags( /** @scrutinizer ignore-type */ $section );
Loading history...
156
					}
157
					if ( $this->context->site_represents_reference ) {
158
						$post_args['publisher'] = $this->context->site_represents_reference;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->context->site_represents_reference can also be of type true. However, the property $site_represents_reference is declared as type array|false. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
159
					}
160
					$image_url = get_the_post_thumbnail_url( $post_id, 'lsx-thumbnail-wide' );
161
					if ( false !== $image_url ) {
162
						$post_args['image'] = $image_url;
163
					}
164
					$posts_array = LSX_Schema_Utils::add_article( $posts_array, $post_id, $this->context, $post_args );
0 ignored issues
show
The method add_article() does not exist on LSX_Schema_Utils. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

164
					/** @scrutinizer ignore-call */ 
165
     $posts_array = LSX_Schema_Utils::add_article( $posts_array, $post_id, $this->context, $post_args );

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.

Loading history...
165
				}
166
				if ( ! empty( $posts_array ) ) {
167
					$data[ $data_key ] = $posts_array;
168
				}
169
			}
170
			return $data;
171
		}
172
		/**
173
		 * Adds the Project and Testimonials attached to the Team Member
174
		 *
175
		 * @param array $data
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
176
		 *
177
		 * @return array $data
178
		 */
179
		public function add_connections( $data ) {
180
			$connections_array = array();
181
			if ( $this->is_top_level ) {
182
				$connections_array = $this->add_regions( $connections_array );
183
				$connections_array = $this->add_accommodation( $connections_array );
184
				if ( ! empty( $connections_array ) ) {
185
					$data['containsPlace'] = $connections_array;
186
				}
187
			} else {
188
				$connections_array             = $this->add_countries( $connections_array );
189
				$data['containedInPlace'] = $connections_array;
190
				$connections_array          = array();
191
				$connections_array          = $this->add_accommodation( $connections_array );
192
				$data['containsPlace'] = $connections_array;
193
			}
194
			return $data;
195
		}
196
		/**
197
		 * Adds the terms for the taxonomy
198
		 *
199
		 * @param array $data     Review data.
200
		 * @param array $data_key the parameter name you wish to assign it to.
201
		 * @param array $taxonomy the taxonomy to grab terms for.
202
		 *
203
		 * @return array $data Review data.
204
		 */
205
		public function add_taxonomy_terms( $data, $data_key, $taxonomy ) {
206
			/**
207
			 * Filter: 'lsx_schema_' . $this->post_type . '_' . $data_key . '_taxonomy' - Allow changing the taxonomy used to assign keywords to a post type Review data.
208
			 *
209
			 * @api string $taxonomy The chosen taxonomy.
210
			 */
211
			$taxonomy = apply_filters( 'lsx_schema_' . $this->post_type . '_' . $data_key . '_taxonomy', $taxonomy );
0 ignored issues
show
Are you sure $data_key of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

211
			$taxonomy = apply_filters( 'lsx_schema_' . $this->post_type . '_' . /** @scrutinizer ignore-type */ $data_key . '_taxonomy', $taxonomy );
Loading history...
212
			return LSX_Schema_Utils::add_terms( $data, $this->context->id, $data_key, $taxonomy );
0 ignored issues
show
$data_key of type array is incompatible with the type string expected by parameter $key of LSX_Schema_Utils::add_terms(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

212
			return LSX_Schema_Utils::add_terms( $data, $this->context->id, /** @scrutinizer ignore-type */ $data_key, $taxonomy );
Loading history...
It seems like $taxonomy can also be of type array; however, parameter $taxonomy of LSX_Schema_Utils::add_terms() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

212
			return LSX_Schema_Utils::add_terms( $data, $this->context->id, $data_key, /** @scrutinizer ignore-type */ $taxonomy );
Loading history...
213
		}
214
		/**
215
		 * Adds the custom field value for the supplied key
216
		 *
217
		 * @param array   $data     Schema data.
218
		 * @param string  $data_key the parameter name you wish to assign it to.
219
		 * @param string  $meta_key the taxonomy to grab terms for.
220
		 * @param boolean $single   A single custom field or an array
0 ignored issues
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
221
		 *
222
		 * @return array $data Review data.
223
		 */
224
		public function add_custom_field( $data, $data_key, $meta_key, $single = true ) {
225
			$value = get_post_meta( $this->context->id, $meta_key, $single );
0 ignored issues
show
$this->context->id of type string is incompatible with the type integer expected by parameter $post_id of get_post_meta(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

225
			$value = get_post_meta( /** @scrutinizer ignore-type */ $this->context->id, $meta_key, $single );
Loading history...
226
			if ( '' !== $value && false !== $value ) {
227
				$data[ $data_key ] = $value;
228
			}
229
			return $data;
230
		}
231
	}
232
}
233