Issues (87)

client/jsonapi/customer/review/standard.php (2 issues)

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020-2026
6
 * @package Client
7
 * @subpackage JsonApi
8
 */
9
10
11
$enc = $this->encoder();
12
13
$target = $this->config( 'client/jsonapi/url/target' );
14
$cntl = $this->config( 'client/jsonapi/url/controller', 'jsonapi' );
15
$action = $this->config( 'client/jsonapi/url/action', 'get' );
16
$config = $this->config( 'client/jsonapi/url/config', [] );
17
18
19
$ref = array( 'resource', 'id', 'related', 'relatedid', 'filter', 'page', 'sort', 'include', 'fields' );
20
$params = array_intersect_key( $this->param(), array_flip( $ref ) );
21
22
$pretty = $this->param( 'pretty' ) ? JSON_PRETTY_PRINT : 0;
23
$fields = $this->param( 'fields', [] );
24
25
foreach( (array) $fields as $resource => $list ) {
26
	$fields[$resource] = array_flip( explode( ',', $list ) );
27
}
28
29
30
$entryFcn = function( \Aimeos\MShop\Review\Item\Iface $item ) use ( $fields, $target, $cntl, $action, $config )
31
{
32
	$relid = $item->getId();
33
	$attributes = $item->toArray();
34
	$id = $this->get( 'customerid' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
35
	$params = array( 'resource' => 'customer', 'id' => $id, 'related' => 'review', 'relatedid' => $relid );
36
	$rtype = 'review';
37
38
	if( isset( $fields[$rtype] ) ) {
39
		$attributes = array_intersect_key( $attributes, $fields[$rtype] );
40
	}
41
42
	$entry = array(
43
		'id' => $relid,
44
		'type' => $rtype,
45
		'links' => array(
46
			'self' => array(
47
				'href' => $this->url( $target, $cntl, $action, $params, [], $config ),
48
				'allow' => array( 'DELETE', 'GET', 'PATCH' ),
49
			),
50
		),
51
		'attributes' => $attributes,
52
	);
53
54
	return $entry;
55
};
56
57
58
?>
59
{
60
	"meta": {
61
		"total": <?= $this->get( 'total', 0 ); ?>,
62
		"prefix": <?= json_encode( $this->get( 'prefix' ) ); ?>,
63
		"content-baseurl": "<?= $this->config( 'resource/fs/baseurl' ); ?>",
64
		"content-baseurls": {
65
			"fs-media": "<?= $this->config( 'resource/fs-media/baseurl' ) ?>",
66
			"fs-mimeicon": "<?= $this->config( 'resource/fs-mimeicon/baseurl' ) ?>",
67
			"fs-theme": "<?= $this->config( 'resource/fs-theme/baseurl' ) ?>"
68
		}
69
		<?php if( $this->csrf()->name() != '' ) : ?>
70
			, "csrf": {
71
				"name": "<?= $this->csrf()->name(); ?>",
72
				"value": "<?= $this->csrf()->value(); ?>"
73
			}
74
		<?php endif; ?>
75
76
	},
77
	"links": {
78
		"self": "<?= $this->url( $target, $cntl, $action, $params, [], $config ); ?>",
79
		"related": "<?= $this->url( $target, $cntl, $action, map( $params )->except( 'relatedid' )->toArray(), [], $config ); ?>"
0 ignored issues
show
'relatedid' of type string is incompatible with the type iterable expected by parameter $keys of Aimeos\Map::except(). ( Ignorable by Annotation )

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

79
		"related": "<?= $this->url( $target, $cntl, $action, map( $params )->except( /** @scrutinizer ignore-type */ 'relatedid' )->toArray(), [], $config ); ?>"
Loading history...
80
	}
81
	<?php if( isset( $this->errors ) ) : ?>
82
		,"errors": <?= json_encode( $this->errors, $pretty ); ?>
83
84
	<?php elseif( isset( $this->items ) ) : ?>
85
		<?php
86
			$data = [];
87
			$items = $this->get( 'items', [] );
88
89
			if( is_map( $items ) )
90
			{
91
				foreach( $items as $item ) {
92
					$data[] = $entryFcn( $item );
93
				}
94
			}
95
			else
96
			{
97
				$data = $entryFcn( $items );
98
			}
99
		?>
100
101
		,"data": <?= json_encode( $data, $pretty ); ?>
102
103
	<?php endif; ?>
104
105
}
106