Skip to content

Commit b6fa6dc

Browse files
committed
Linter and code cleanup
1 parent cc5a562 commit b6fa6dc

29 files changed

+163
-115
lines changed

src/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function generate()
5959
{
6060
$properties = $this->getProperties();
6161

62-
return $properties ? "<script type=\"application/ld+json\">" . json_encode($properties,JSON_HEX_APOS | JSON_UNESCAPED_UNICODE) . "</script>" : '';
62+
return $properties ? "<script type=\"application/ld+json\">" . json_encode($properties, JSON_HEX_APOS | JSON_UNESCAPED_UNICODE) . "</script>" : '';
6363
}
6464

6565
/**

src/ContextTypes/AbstractContext.php

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function fill($attributes)
102102
* Set sameAs Attribute
103103
*
104104
* @param mixed $value
105+
*
105106
* @return mixed
106107
*/
107108
protected function setSameAsAttribute($value)
@@ -122,8 +123,9 @@ public function getProperties()
122123
/**
123124
* Get an item from properties.
124125
*
125-
* @param string $key
126-
* @param mixed $default
126+
* @param string $key
127+
* @param mixed $default
128+
*
127129
* @return mixed
128130
*/
129131
public function getProperty($key, $default = null)
@@ -134,9 +136,10 @@ public function getProperty($key, $default = null)
134136
/**
135137
* Set property value in attributes.
136138
*
137-
* @param string $key
138-
* @param mixed $property
139-
* @param mixed $value
139+
* @param string $key
140+
* @param mixed $property
141+
* @param mixed $value
142+
*
140143
* @return mixed
141144
*/
142145
protected function setProperty($key, $property, $value = null)
@@ -179,7 +182,8 @@ protected function setProperty($key, $property, $value = null)
179182
/**
180183
* Set context type.
181184
*
182-
* @param string $type
185+
* @param string $type
186+
*
183187
* @return void
184188
*/
185189
protected function setType($type)
@@ -190,8 +194,9 @@ protected function setType($type)
190194
/**
191195
* Get nested context array.
192196
*
193-
* @param string $class
194-
* @param array $attributes
197+
* @param string $class
198+
* @param array $attributes
199+
*
195200
* @return array
196201
*/
197202
protected function getNestedContext($class, $attributes = null)
@@ -209,16 +214,17 @@ protected function getNestedContext($class, $attributes = null)
209214
/**
210215
* Filter nested context array.
211216
*
212-
* @param array $properties
217+
* @param array $properties
218+
*
213219
* @return array
214220
*/
215221
protected function filterNestedContext(array $properties = [])
216222
{
217-
$func = function($value, $key) {
223+
$func = function ($value, $key) {
218224
return ($value && $key !== '@context');
219225
};
220226

221-
if (!defined('ARRAY_FILTER_USE_BOTH')) {
227+
if (defined('ARRAY_FILTER_USE_BOTH') === false) {
222228
$return = [];
223229
foreach ($properties as $k => $v) {
224230
if (call_user_func($func, $v, $k)) {
@@ -235,7 +241,8 @@ protected function filterNestedContext(array $properties = [])
235241
/**
236242
* Determine if a get mutator exists for an attribute.
237243
*
238-
* @param string $key
244+
* @param string $key
245+
*
239246
* @return bool
240247
*/
241248
protected function hasGetMutator($key)
@@ -246,8 +253,9 @@ protected function hasGetMutator($key)
246253
/**
247254
* Get the value of an attribute using its mutator.
248255
*
249-
* @param string $key
250-
* @param mixed $args
256+
* @param string $key
257+
* @param mixed $args
258+
*
251259
* @return mixed
252260
*/
253261
protected function mutateAttribute($key, $args)
@@ -258,7 +266,8 @@ protected function mutateAttribute($key, $args)
258266
/**
259267
* Get mutator name from string.
260268
*
261-
* @param string $value
269+
* @param string $value
270+
*
262271
* @return string
263272
*/
264273
protected function getMutatorName($value)
@@ -271,8 +280,9 @@ protected function getMutatorName($value)
271280
/**
272281
* Get property value from attributes.
273282
*
274-
* @param array $template
275-
* @param array $props
283+
* @param array $template
284+
* @param array $props
285+
*
276286
* @return mixed
277287
*/
278288
protected function mapProperty(array $template = [], $props = [])
@@ -282,7 +292,7 @@ protected function mapProperty(array $template = [], $props = [])
282292
return null;
283293
}
284294

285-
foreach($template as $key => $value) {
295+
foreach ($template as $key => $value) {
286296
if ($key[0] !== '@') {
287297
$template[$key] = $this->getArrValue($props, $key, '');
288298
}
@@ -294,20 +304,21 @@ protected function mapProperty(array $template = [], $props = [])
294304
/**
295305
* Trim a string to a given number of words
296306
*
297-
* @param string $string
298-
* @param int $limit
299-
* @param string $pad
300-
* @param string $break
307+
* @param string $string
308+
* @param int $limit
309+
* @param string $pad
310+
* @param string $break
311+
*
301312
* @return string
302313
*/
303314
protected function truncate($string, $limit, $pad = '...', $break = ' ')
304315
{
305316
// return with no change if string is shorter than $limit
306-
if(strlen($string) <= $limit) return $string;
317+
if (strlen($string) <= $limit) return $string;
307318

308319
// is $break present between $limit and the end of the string?
309-
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
310-
if($breakpoint < strlen($string) - 1) {
320+
if (false !== ($breakpoint = strpos($string, $break, $limit))) {
321+
if ($breakpoint < strlen($string) - 1) {
311322
$string = substr($string, 0, $breakpoint) . $pad;
312323
}
313324
}
@@ -318,9 +329,10 @@ protected function truncate($string, $limit, $pad = '...', $break = ' ')
318329
/**
319330
* Get an item from an array.
320331
*
321-
* @param array $array
322-
* @param string $key
323-
* @param mixed $default
332+
* @param array $array
333+
* @param string $key
334+
* @param mixed $default
335+
*
324336
* @return mixed
325337
*/
326338
protected function getArrValue(array $array, $key, $default = null)

src/ContextTypes/Article.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace JsonLd\ContextTypes;
44

5+
/**
6+
* https://schema.org/Article
7+
*/
58
class Article extends CreativeWork
69
{
710
/**
811
* Property structure
9-
* reference: https://schema.org/Article (alphabetical order)
1012
*
1113
* @var array
1214
*/
@@ -28,14 +30,17 @@ class Article extends CreativeWork
2830
*/
2931
public function __construct(array $attributes, array $extendedStructure = [])
3032
{
31-
parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure));
33+
parent::__construct(
34+
$attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)
35+
);
3236
}
3337

3438
/**
3539
* Set the description attribute.
3640
*
37-
* @param string $txt
38-
* @return array
41+
* @param string $txt
42+
*
43+
* @return string
3944
*/
4045
protected function setDescriptionAttribute($txt)
4146
{
@@ -45,8 +50,9 @@ protected function setDescriptionAttribute($txt)
4550
/**
4651
* Set the text attribute.
4752
*
48-
* @param string $txt
49-
* @return array
53+
* @param string $txt
54+
*
55+
* @return string
5056
*/
5157
protected function setTextAttribute($txt)
5258
{
@@ -56,8 +62,9 @@ protected function setTextAttribute($txt)
5662
/**
5763
* Set the article body attribute.
5864
*
59-
* @param string $txt
60-
* @return array
65+
* @param string $txt
66+
*
67+
* @return string
6168
*/
6269
protected function setArticleBodyAttribute($txt)
6370
{

src/ContextTypes/BreadcrumbList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ class BreadcrumbList extends AbstractContext
1616
/**
1717
* Set the canonical URL of the article page.
1818
*
19-
* @param array $items
19+
* @param array $items
20+
*
2021
* @return array
2122
*/
2223
protected function setItemListElementAttribute($items)
2324
{
24-
foreach($items as $pos=>$item) {
25+
foreach ($items as $pos => $item) {
2526
$items[$pos] = $this->getNestedContext(ListItem::class, [
2627
'position' => $pos + 1,
2728
'item' => $item

src/ContextTypes/Comment.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace JsonLd\ContextTypes;
44

5-
class Comment extends CreativeWork
5+
/**
6+
* https://schema.org/Comment
7+
*/
8+
class Comment extends CreativeWork
69
{
710
/**
8-
* Property structure.
9-
* reference: https://schema.org/Comment (alphabetical order)
11+
* Property structure
1012
*
1113
* @var array
1214
*/

src/ContextTypes/Corporation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Corporation extends Organization
2121
*/
2222
public function __construct(array $attributes, array $extendedStructure = [])
2323
{
24-
parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure));
24+
parent::__construct(
25+
$attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)
26+
);
2527
}
26-
2728
}

src/ContextTypes/CreativeWork.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace JsonLd\ContextTypes;
44

5+
/**
6+
* https://schema.org/CreativeWork
7+
*/
58
class CreativeWork extends Thing
69
{
710
/**
811
* Property structure
9-
* reference: https://schema.org/CreativeWork (alphabetical order)
1012
*
1113
* @var array
1214
*/
@@ -49,7 +51,8 @@ public function __construct(array $attributes, array $extendedStructure = [])
4951
/**
5052
* Set the article body attribute.
5153
*
52-
* @param string $txt
54+
* @param string $txt
55+
*
5356
* @return array
5457
*/
5558
protected function setTextAttribute($txt)
@@ -61,6 +64,7 @@ protected function setTextAttribute($txt)
6164
* Set the authors
6265
*
6366
* @param array $items
67+
*
6468
* @return array
6569
*/
6670
protected function setAuthorAttribute($items)
@@ -78,6 +82,7 @@ protected function setAuthorAttribute($items)
7882
* Set the comments
7983
*
8084
* @param array $items
85+
*
8186
* @return array
8287
*/
8388
protected function setCommentAttribute($items)
@@ -95,6 +100,7 @@ protected function setCommentAttribute($items)
95100
* Set the reviews
96101
*
97102
* @param array $items
103+
*
98104
* @return array
99105
*/
100106
protected function setReviewAttribute($items)

src/ContextTypes/Event.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public function __construct(array $attributes, array $extendedStructure = [])
3434
/**
3535
* Set offers attributes.
3636
*
37-
* @param mixed $values
37+
* @param mixed $values
38+
*
3839
* @return array
3940
*/
4041
protected function setOffersAttribute($values)
4142
{
4243
if (is_array($values)) {
43-
foreach($values as $key => $value) {
44+
foreach ($values as $key => $value) {
4445
$values[$key] = $this->mapProperty([
4546
'name' => '',
4647
'price' => '',

src/ContextTypes/Invoice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
namespace JsonLd\ContextTypes;
4+
35
class Invoice extends AbstractContext
46
{
57
/**

src/ContextTypes/ListItem.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class ListItem extends AbstractContext
1717
/**
1818
* Set item in list.
1919
*
20-
* @param array $item
20+
* @param array $item
21+
*
2122
* @return array
2223
*/
2324
protected function setItemAttribute($item)

src/ContextTypes/LocalBusiness.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class LocalBusiness extends AbstractContext
2929
/**
3030
* Set the opening hours of the business.
3131
*
32-
* @param array $items
32+
* @param array $items
33+
*
3334
* @return array
3435
*/
3536
protected function setOpeningHoursAttribute($items)

0 commit comments

Comments
 (0)