Issues (1110)

classes/class-to-specials-schema.php (33 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-lsx-to-specials-schema.php, but found class-to-specials-schema.php.
Loading history...
2
/**
3
 * The Trip Schema for Tours
4
 *
5
 * @package tour-operator
6
 */
7
8
/**
9
 * Returns schema Review data.
10
 *
11
 * @since 10.2
12
 */
13
class LSX_TO_Specials_Schema extends LSX_TO_Schema_Graph_Piece {
14
15
	/**
16
	 * Constructor.
17
	 *
18
	 * @param \WPSEO_Schema_Context $context A value object with context variables.
19
	 */
20
	public function __construct( WPSEO_Schema_Context $context ) {
0 ignored issues
show
The type WPSEO_Schema_Context 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...
Expected 2 blank lines before function; 1 found
Loading history...
21
		$this->post_type = 'special';
0 ignored issues
show
The property post_type does not exist on LSX_TO_Specials_Schema. Did you mean post_types_singular?
Loading history...
22
		parent::__construct( $context );
0 ignored issues
show
The call to LSX_TO_Specials::__construct() has too many arguments starting with $context. ( Ignorable by Annotation )

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

22
		parent::/** @scrutinizer ignore-call */ 
23
          __construct( $context );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
23
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
24
25
	/**
26
	 * Returns Review data.
27
	 *
28
	 * @return array $data Review data.
29
	 */
30
	public function generate() {
31
		$tour_list  = get_post_meta( get_the_ID(), 'tour_to_special', false );
0 ignored issues
show
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept integer, 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

31
		$tour_list  = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), 'tour_to_special', false );
Loading history...
32
		$accom_list = get_post_meta( get_the_ID(), 'accommodation_to_special', false );
33
		$data       = array(
34
			'@type'            => array(
35
				'Offer',
36
			),
37
			'@id'              => $this->context->canonical . '#special',
0 ignored issues
show
Bug Best Practice introduced by
The property context does not exist on LSX_TO_Specials_Schema. Did you maybe forget to declare it?
Loading history...
38
			'name'             => $this->post->post_title,
0 ignored issues
show
Bug Best Practice introduced by
The property post does not exist on LSX_TO_Specials_Schema. Did you maybe forget to declare it?
Loading history...
39
			'description'      => wp_strip_all_tags( $this->post->post_content ),
40
			'url'              => $this->post_url,
0 ignored issues
show
Bug Best Practice introduced by
The property post_url does not exist on LSX_TO_Specials_Schema. Did you maybe forget to declare it?
Loading history...
41
			'mainEntityOfPage' => array(
42
				'@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH,
0 ignored issues
show
The type WPSEO_Schema_IDs 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...
43
			),
44
		);
45
46
		if ( $this->context->site_represents_reference ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
47
			$data['offeredBy'] = $this->context->site_represents_reference;
48
		}
49
50
		$data = $this->add_custom_field( $data, 'availabilityStarts', 'booking_validity_start' );
0 ignored issues
show
The method add_custom_field() does not exist on LSX_TO_Specials_Schema. ( Ignorable by Annotation )

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

50
		/** @scrutinizer ignore-call */ 
51
  $data = $this->add_custom_field( $data, 'availabilityStarts', 'booking_validity_start' );

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...
51
		$data = $this->add_custom_field( $data, 'availabilityEnds', 'booking_validity_end' );
52
		$data = $this->add_custom_field( $data, 'priceValidUntil', 'booking_validity_end' );
53
		$data = $this->add_custom_field( $data, 'priceValidUntil', 'booking_validity_end' );
54
		$data = $this->get_price( $data );
0 ignored issues
show
The method get_price() does not exist on LSX_TO_Specials_Schema. ( Ignorable by Annotation )

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

54
		/** @scrutinizer ignore-call */ 
55
  $data = $this->get_price( $data );

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...
55
56
		$data['itemOffered'] = \lsx\legacy\Schema_Utils::get_item_reviewed( $tour_list, 'Product' );
0 ignored issues
show
It seems like $tour_list can also be of type false; however, parameter $items of lsx\legacy\Schema_Utils::get_item_reviewed() does only seem to accept array, 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

56
		$data['itemOffered'] = \lsx\legacy\Schema_Utils::get_item_reviewed( /** @scrutinizer ignore-type */ $tour_list, 'Product' );
Loading history...
57
		$data['itemOffered'] = \lsx\legacy\Schema_Utils::get_item_reviewed( $accom_list, 'Product' );
58
59
		$data = $this->add_articles( $data );
0 ignored issues
show
The method add_articles() does not exist on LSX_TO_Specials_Schema. ( Ignorable by Annotation )

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

59
		/** @scrutinizer ignore-call */ 
60
  $data = $this->add_articles( $data );

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...
60
		$data = \lsx\legacy\Schema_Utils::add_image( $data, $this->context );
61
62
		return $data;
63
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
64
65
	/**
66
	 * Gets the single special post and adds it as a special "Offer".
67
	 *
68
	 * @param  array $data An array of offers already added.
69
	 * @return array $data
70
	 */
71
	public function get_price( $data ) {
72
		$price         = get_post_meta( $this->context->id, 'price', true );
0 ignored issues
show
Bug Best Practice introduced by
The property context does not exist on LSX_TO_Specials_Schema. Did you maybe forget to declare it?
Loading history...
73
		$currency      = 'USD';
74
		$tour_operator = tour_operator();
75
		if ( is_object( $tour_operator ) && isset( $tour_operator->options['general'] ) && is_array( $tour_operator->options['general'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
76
			if ( isset( $tour_operator->options['general']['currency'] ) && ! empty( $tour_operator->options['general']['currency'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
77
				$currency = $tour_operator->options['general']['currency'];
78
			}
79
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
80
		if ( false !== $price && '' !== $price ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
81
			$data['price']         = $price;
82
			$data['priceCurrency'] = $currency;
83
			$data['category']      = __( 'Special', 'tour-operator-specials' );
84
			$data['availability']  = 'https://schema.org/LimitedAvailability';
85
86
			$price_type = get_post_meta( $this->context->id, 'price_type', true );
87
			if ( false !== $price_type && '' !== $price_type && 'none' !== $price_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
88
				$data['PriceSpecification'] = lsx_to_get_price_type_label( $price_type );
89
			}
90
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
91
		return $data;
92
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
93
}
94