Issues (1110)

classes/class-to-specials-schema.php (1 issue)

1
<?php
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 ) {
21
		$this->post_type = 'special';
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
	}
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 );
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',
38
			'name'             => $this->post->post_title,
39
			'description'      => wp_strip_all_tags( $this->post->post_content ),
40
			'url'              => $this->post_url,
41
			'mainEntityOfPage' => array(
42
				'@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH,
43
			),
44
		);
45
46
		if ( $this->context->site_represents_reference ) {
47
			$data['offeredBy'] = $this->context->site_represents_reference;
48
		}
49
50
		$data = $this->add_custom_field( $data, 'availabilityStarts', 'booking_validity_start' );
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 );
55
56
		$data['itemOffered'] = \lsx\legacy\Schema_Utils::get_item_reviewed( $tour_list, 'Product' );
57
		$data['itemOffered'] = \lsx\legacy\Schema_Utils::get_item_reviewed( $accom_list, 'Product' );
58
59
		$data = $this->add_articles( $data );
60
		$data = \lsx\legacy\Schema_Utils::add_image( $data, $this->context );
61
62
		return $data;
63
	}
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 );
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'] ) ) {
76
			if ( isset( $tour_operator->options['general']['currency'] ) && ! empty( $tour_operator->options['general']['currency'] ) ) {
77
				$currency = $tour_operator->options['general']['currency'];
78
			}
79
		}
80
		if ( false !== $price && '' !== $price ) {
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 ) {
88
				$data['PriceSpecification'] = lsx_to_get_price_type_label( $price_type );
89
			}
90
		}
91
		return $data;
92
	}
93
}
94