From 96f224ff9f6b65d31421cef73a1372e38d099604 Mon Sep 17 00:00:00 2001 From: Boly38 Date: Fri, 6 Jul 2018 14:13:49 +0200 Subject: [PATCH 01/10] Fixes #41 an Article with N Comments - use heritage benefits onto CreativeWork, Sculpture, Article, Comment - allow to set multiple comments to an Article (or CreativeWork) - add ld json generation and asserts on each not null property --- src/ContextTypes/AbstractContext.php | 2 +- src/ContextTypes/Article.php | 37 +++++------ src/ContextTypes/Comment.php | 28 ++++++++ src/ContextTypes/CreativeWork.php | 48 ++++++++++++-- src/ContextTypes/Sculpture.php | 24 +++++++ src/ContextTypes/Thing.php | 9 ++- tests/ContextTypes/ArticleTest.php | 97 ++++++++++++++++++++-------- tests/ContextTypes/SculptureTest.php | 89 +++++++++++++++++++++++++ tests/TestCase.php | 22 +++++++ 9 files changed, 297 insertions(+), 59 deletions(-) create mode 100644 src/ContextTypes/Comment.php create mode 100644 src/ContextTypes/Sculpture.php create mode 100644 tests/ContextTypes/SculptureTest.php diff --git a/src/ContextTypes/AbstractContext.php b/src/ContextTypes/AbstractContext.php index 5d1d474..790bc74 100644 --- a/src/ContextTypes/AbstractContext.php +++ b/src/ContextTypes/AbstractContext.php @@ -168,7 +168,7 @@ protected function setProperty($key, $property, $value = null) } // Map properties to object - if (is_array($value)) { + if ($property != null && is_array($property) && is_array($value)) { return $this->properties[$key] = $this->mapProperty($property, $value); } diff --git a/src/ContextTypes/Article.php b/src/ContextTypes/Article.php index 4114379..019c445 100644 --- a/src/ContextTypes/Article.php +++ b/src/ContextTypes/Article.php @@ -2,41 +2,34 @@ namespace JsonLd\ContextTypes; -class Article extends AbstractContext +class Article extends CreativeWork { /** * Property structure + * reference: https://schema.org/Article (alphabetical order) * * @var array */ - protected $structure = [ - 'name' => null, - 'url' => null, - 'description' => null, - - 'image' => ImageObject::class, - 'video' => VideoObject::class, - 'thumbnailUrl' => null, - 'text' => null, - 'review' => Review::class, - 'publisher' => Organization::class, - 'keywords' => null, - 'inLanguage' => null, - 'dateCreated' => null, - 'dateModified' => null, - 'datePublished' => null, - 'author' => Person::class, - 'aggregateRating' => AggregateRating::class, - + private $extendedStructure = [ 'articleBody' => null, 'articleSection' => null, 'pageEnd' => null, 'pageStart' => null, 'pagination' => null, - 'mainEntityOfPage' => WebPage::class, - 'headline' => null, + 'wordCount' => null ]; + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + } + /** * Set the description attribute. * diff --git a/src/ContextTypes/Comment.php b/src/ContextTypes/Comment.php new file mode 100644 index 0000000..669d4e3 --- /dev/null +++ b/src/ContextTypes/Comment.php @@ -0,0 +1,28 @@ + null, + 'upvoteCount' => null + ]; + + + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + } +} diff --git a/src/ContextTypes/CreativeWork.php b/src/ContextTypes/CreativeWork.php index 338a0e2..03d792f 100644 --- a/src/ContextTypes/CreativeWork.php +++ b/src/ContextTypes/CreativeWork.php @@ -2,32 +2,50 @@ namespace JsonLd\ContextTypes; -class CreativeWork extends AbstractContext +class CreativeWork extends Thing { /** * Property structure + * reference: https://schema.org/CreativeWork (alphabetical order) * * @var array */ - protected $structure = [ - 'name' => null, - 'url' => null, + private $extendedStructure = [ + 'about' => Thing::class, 'aggregateRating' => AggregateRating::class, + 'alternativeHeadline' => null, 'author' => Person::class, + 'comment' => Comment::class, + 'commentCount' => null, 'creator' => Person::class, 'dateCreated' => null, 'dateModified' => null, 'datePublished' => null, 'headline' => null, - 'image' => ImageObject::class, 'inLanguage' => null, + 'keywords' => null, + 'mainEntity' => Thing::class, 'publisher' => Organization::class, 'review' => Review::class, 'text' => null, 'thumbnailUrl' => null, - 'video' => VideoObject::class, + 'video' => VideoObject::class ]; + + + + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + } + /** * Set the article body attribute. * @@ -38,4 +56,22 @@ protected function setTextAttribute($txt) { return $this->truncate($txt, 260); } + + /** + * Set the comments + * + * @param array $items + * @return array + */ + protected function setCommentAttribute($items) + { + if (!is_array($items)) { + return $items; + } + + return array_map(function ($item) { + return $this->getNestedContext(Comment::class, $item); + }, $items); + } + } \ No newline at end of file diff --git a/src/ContextTypes/Sculpture.php b/src/ContextTypes/Sculpture.php new file mode 100644 index 0000000..464294f --- /dev/null +++ b/src/ContextTypes/Sculpture.php @@ -0,0 +1,24 @@ +structure, $this->extendedStructure, $extendedStructure)); + } +} diff --git a/src/ContextTypes/Thing.php b/src/ContextTypes/Thing.php index e241537..27f3c03 100644 --- a/src/ContextTypes/Thing.php +++ b/src/ContextTypes/Thing.php @@ -6,15 +6,18 @@ class Thing extends AbstractContext { /** * Property structure + * reference: https://schema.org/Thing (alphabetical order) * * @var array */ protected $structure = [ - 'name' => null, 'alternateName' => null, 'description' => null, - 'image' => null, - 'url' => null, + 'image' => ImageObject::class, + 'mainEntityOfPage' => WebPage::class, + 'name' => null, + 'sameAs' => null, + 'url' => null ]; /** diff --git a/tests/ContextTypes/ArticleTest.php b/tests/ContextTypes/ArticleTest.php index f990aa9..83d05f1 100644 --- a/tests/ContextTypes/ArticleTest.php +++ b/tests/ContextTypes/ArticleTest.php @@ -9,7 +9,7 @@ class ArticleTest extends TestCase protected $class = \JsonLd\ContextTypes\Article::class; protected $attributes = [ - 'name' => 'More than That', + 'name' => 'articleNComments', 'url' => 'https://google.com/1-article', 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.', 'image' => [ @@ -38,6 +38,17 @@ class ArticleTest extends TestCase ], 'keywords' => 'Lorem,ipsum,dolor', 'inLanguage' => 'en', + 'commentCount' => 2, + 'comment' => [ + ['@type' => 'Comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Joe'], + 'text' => 'first comment', + 'dateCreated' => '2018-06-14T21:40:00+02:00'], + ['@type' => 'Comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Bis'], + 'text' => 'second comment', + 'dateCreated' => '2018-06-14T23:23:00+02:00'] + ], 'dateCreated' => '2013-10-04T00:00', 'dateModified' => '2013-10-04T00:00', 'datePublished' => '2013-10-04T00:00', @@ -50,6 +61,52 @@ class ArticleTest extends TestCase 'headline' => 'eiusmod tempor incididunt ut labore et dolore magna aliqua.', ]; + /** + * @test + */ + public function shouldHaveThingName() + { + $context = $this->make(); + + $this->assertEquals('articleNComments', $context->getProperty('name')); + } + + /** + * @test + */ + public function shouldHaveThingMainEntityOfPageObject() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'WebPage', + '@id' => 'https://blogspot.com/100-article', + ], $context->getProperty('mainEntityOfPage')); + } + + /** + * @test + */ + public function shouldHaveCreativeWorkInLanguage() + { + $context = $this->make(); + + $this->assertEquals('en', $context->getProperty('inLanguage')); + } + + /** + * @test + */ + public function shouldHaveCreativeWorkAuthorObject() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'Person', + 'name' => 'Joe Joe', + ], $context->getProperty('author')); + } + /** * @test */ @@ -145,36 +202,22 @@ public function shouldHaveKeywords() /** * @test */ - public function shouldHaveInLanguage() - { - $context = $this->make(); - - $this->assertEquals('en', $context->getProperty('inLanguage')); - } - - /** - * @test - */ - public function shouldHaveAuthorObject() + public function shouldHave2CommentsArray() { $context = $this->make(); $this->assertEquals([ - '@type' => 'Person', - 'name' => 'Joe Joe', - ], $context->getProperty('author')); - } - - /** - * @test - */ - public function shouldHaveMainEntityOfPageObject() - { - $context = $this->make(); - + '@type' => 'Comment', + 'text' => 'first comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Joe'], + 'dateCreated' => '2018-06-14T21:40:00+02:00', + ], $context->getProperty('comment')[0]); $this->assertEquals([ - '@type' => 'WebPage', - '@id' => 'https://blogspot.com/100-article', - ], $context->getProperty('mainEntityOfPage')); + '@type' => 'Comment', + 'text' => 'second comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Bis'], + 'dateCreated' => '2018-06-14T23:23:00+02:00', + ], $context->getProperty('comment')[1]); } + } diff --git a/tests/ContextTypes/SculptureTest.php b/tests/ContextTypes/SculptureTest.php new file mode 100644 index 0000000..78fd79a --- /dev/null +++ b/tests/ContextTypes/SculptureTest.php @@ -0,0 +1,89 @@ + 'https://exemple.com/sclpture?id=1234', + 'author' => [ + '@type' => 'Person', + 'name' => 'Rodin', + ], + 'text' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.', + 'commentCount' => 2, + 'comment' => [ + ['@type' => 'Comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Joe'], + 'text' => 'first comment', + 'dateCreated' => '2018-06-14T21:40:00+02:00'], + ['@type' => 'Comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Bis'], + 'text' => 'second comment', + 'dateCreated' => '2018-06-14T23:23:00+02:00'] + ], + 'inLanguage' => 'jp', + 'dateCreated' => '2013-10-04T00:00', + 'name' => 'sculptureNComments' + + ]; + + + /** + * @test + */ + public function shouldHaveThingName() + { + $context = $this->make(); + + $this->assertEquals('sculptureNComments', $context->getProperty('name')); + } + + /** + * @test + */ + public function shouldHaveCreativeWorkInLanguage() + { + $context = $this->make(); + + $this->assertEquals('jp', $context->getProperty('inLanguage')); + } + + /** + * @test + */ + public function shouldHaveCreativeWorkAuthorObject() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'Person', + 'name' => 'Rodin', + ], $context->getProperty('author')); + } + + /** + * @test + */ + public function shouldHave2CommentsArray() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'Comment', + 'text' => 'first comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Joe'], + 'dateCreated' => '2018-06-14T21:40:00+02:00', + ], $context->getProperty('comment')[0]); + $this->assertEquals([ + '@type' => 'Comment', + 'text' => 'second comment', + 'author' => ['@type' => 'Person', 'name' => 'Joe Bis'], + 'dateCreated' => '2018-06-14T23:23:00+02:00', + ], $context->getProperty('comment')[1]); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index ad3a8e8..b5eb5a8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,4 +20,26 @@ protected function make() { return new $this->class($this->attributes); } + + protected function makeJsonLdContext() + { + return \JsonLd\Context::create($this->class, $this->attributes); + } + + public function testGenerateLdJson() + { + $context = $this->make(); + $jsonLdContext = $this->makeJsonLdContext(); + + $html = $jsonLdContext->generate(); + $properties = $context->getProperties(); + + $this->assertNotNull($html); + foreach ($properties as $k => $v) { + if ($v != null) { + $this->assertContains(json_encode($k), $html); + $this->assertContains(json_encode($v), $html); + } + } + } } \ No newline at end of file From bcc21da0ce527924f7642534cb5e6ee2b8998522 Mon Sep 17 00:00:00 2001 From: Boly38 Date: Mon, 9 Jul 2018 20:56:55 +0200 Subject: [PATCH 02/10] Improve Person and Place with Unit Tests - Person extend Things - Place extend Things - add attributes with unit tests - improve unit test assert method --- src/ContextTypes/Person.php | 55 ++++++- src/ContextTypes/Place.php | 18 ++- .../ContextTypes/PersonSimpleAddressTest.php | 65 +++++++++ tests/ContextTypes/PersonTest.php | 138 ++++++++++++++++++ tests/ContextTypes/PlaceTest.php | 46 ++++++ tests/TestCase.php | 9 ++ 6 files changed, 325 insertions(+), 6 deletions(-) create mode 100644 tests/ContextTypes/PersonSimpleAddressTest.php create mode 100644 tests/ContextTypes/PersonTest.php create mode 100644 tests/ContextTypes/PlaceTest.php diff --git a/src/ContextTypes/Person.php b/src/ContextTypes/Person.php index b663042..608b95f 100644 --- a/src/ContextTypes/Person.php +++ b/src/ContextTypes/Person.php @@ -2,14 +2,63 @@ namespace JsonLd\ContextTypes; -class Person extends AbstractContext +class Person extends Thing { /** * Property structure + * reference: https://schema.org/Person (alphabetical order) * * @var array */ - protected $structure = [ - 'name' => null, + protected $extendedStructure = [ + 'additionalName' => null, + 'address' => null, // PostalAddress or Text + 'affiliation' => null, + 'alumniOf' => null, + 'award' => null, + 'birthDate' => null, + 'birthPlace' => Place::class, + 'brand' => null, + 'children' => Person::class, + 'colleague' => null, + 'contactPoint' => null, + 'deathDate' => null, + 'deathPlace' => Place::class, + 'duns' => null, + 'email' => null, + 'familyName' => null, + 'faxNumber' => null, + 'follows' => Person::class, + 'homeLocation' => Place::class, + 'givenName' => null, + 'jobTitle' => null, + 'parent' => Person::class, + 'telephone' => null, + 'workLocation' => Place::class ]; + + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + } + + /** + * Set the address + * + * @param array $items + * @return array + */ + protected function setAddressAttribute($items) + { + if (!is_array($items)) { + return $items; + } + return $this->getNestedContext(PostalAddress::class, $items); + } } \ No newline at end of file diff --git a/src/ContextTypes/Place.php b/src/ContextTypes/Place.php index 37e568e..e22865a 100644 --- a/src/ContextTypes/Place.php +++ b/src/ContextTypes/Place.php @@ -2,17 +2,29 @@ namespace JsonLd\ContextTypes; -class Place extends AbstractContext +class Place extends Thing { /** * Property structure * * @var array */ - protected $structure = [ - 'name' => null, + protected $extendedStructure = [ 'address' => PostalAddress::class, 'review' => Review::class, 'aggregateRating' => AggregateRating::class, ]; + + + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + } + } diff --git a/tests/ContextTypes/PersonSimpleAddressTest.php b/tests/ContextTypes/PersonSimpleAddressTest.php new file mode 100644 index 0000000..90bfd58 --- /dev/null +++ b/tests/ContextTypes/PersonSimpleAddressTest.php @@ -0,0 +1,65 @@ + 'Anonymous tester', + 'mainEntityOfPage' => [ + 'url' => 'https://example.com/anonymous.html' + ], + 'additionalName' => 'phpUnit hacker', + 'address' => 'rue de gauche' + + ]; + + /** + * @test + */ + public function shouldHaveThingName() + { + $context = $this->make(); + + $this->assertEquals('Anonymous tester', $context->getProperty('name')); + } + + /** + * @test + */ + public function shouldHaveThingMainEntityOfPageObject() + { + $context = $this->make(); + + $this->assertEquals([ + '@type' => 'WebPage', + '@id' => 'https://example.com/anonymous.html', + ], $context->getProperty('mainEntityOfPage')); + } + + /** + * @test + */ + public function shouldHaveAdditionalName() + { + $context = $this->make(); + + $this->assertEquals('phpUnit hacker', $context->getProperty('additionalName')); + } + + /** + * @test + */ + public function shouldHaveAddress() + { + $context = $this->make(); + + $this->assertEquals('rue de gauche', $context->getProperty('address')); + } + + +} diff --git a/tests/ContextTypes/PersonTest.php b/tests/ContextTypes/PersonTest.php new file mode 100644 index 0000000..5551e4f --- /dev/null +++ b/tests/ContextTypes/PersonTest.php @@ -0,0 +1,138 @@ + 'Anonymous tester', + 'description' => 'a man in the middle', + 'mainEntityOfPage' => [ + 'url' => 'https://example.com/anonymous.html' + ], + 'image' => [ + 'url' => 'https://google.com/Doctor.jpg', + 'height' => 800, + 'width' => 800 + ], + 'additionalName' => 'phpUnit hacker', + 'address' => [ + 'addressLocality' => 'Paris', + 'addressCountry' => 'France' + ], + 'award' => 'phpUnit Excellence', + 'birthDate' => '1943-10-04T00:00', + 'birthPlace' => ['name' => 'Paris'], + 'deathDate' => '2013-10-04T00:00', + 'deathPlace' => ['name' => 'London'], + 'email' => 'toto@yoyo.fr', + 'familyName' => 'Dupondt', + 'faxNumber' => '0000000000', + 'follows' => [ 'name' => 'strange follower' ], + 'givenName' => 'Doctor', + 'homeLocation' => [ + 'name' => 'Fluff Hut', + 'address' => [ + 'streetAddress' => '112 Apple St.', + 'addressLocality' => 'Hamden', + 'addressRegion' => 'CT', + 'postalCode' => '06514', + ], + ], + 'jobTitle' => 'tester', + 'parent' => [ 'name' => 'daddy' ], + 'telephone' => '+330102030405' + + ]; + + public function test_should_have_properties() { + + $this->assertPropertyEquals('name', 'Anonymous tester'); + + $this->assertPropertyEquals('description', 'a man in the middle'); + + $this->assertPropertyEquals('mainEntityOfPage', + [ + '@type' => 'WebPage', + '@id' => 'https://example.com/anonymous.html', + ]); + + $this->assertPropertyEquals('image', + [ + '@type' => 'ImageObject', + 'url' => 'https://google.com/Doctor.jpg', + 'height' => 800, + 'width' => 800, + ]); + + $this->assertPropertyEquals('additionalName', 'phpUnit hacker'); + + $this->assertPropertyEquals('address', + [ + '@type' => 'PostalAddress', + 'addressLocality' => 'Paris', + 'addressCountry' => 'France' + ]); + + $this->assertPropertyEquals('award', 'phpUnit Excellence'); + + $this->assertPropertyEquals('birthDate', '1943-10-04T00:00'); + + $this->assertPropertyEquals('birthPlace', + [ + '@type' => 'Place', + 'name' => 'Paris', + ]); + + $this->assertPropertyEquals('deathDate', '2013-10-04T00:00'); + + $this->assertPropertyEquals('deathPlace', + [ + '@type' => 'Place', + 'name' => 'London', + ]); + + $this->assertPropertyEquals('email', 'toto@yoyo.fr'); + + $this->assertPropertyEquals('familyName', 'Dupondt'); + + $this->assertPropertyEquals('faxNumber', '0000000000'); + + $this->assertPropertyEquals('follows', + [ + '@type' => 'Person', + 'name' => 'strange follower' + ]); + + $this->assertPropertyEquals('givenName', 'Doctor'); + + $this->assertPropertyEquals('homeLocation', + [ + '@type' => 'Place', + 'name' => 'Fluff Hut', + 'address' => [ + '@type' => 'PostalAddress', + 'streetAddress' => '112 Apple St.', + 'addressLocality' => 'Hamden', + 'addressRegion' => 'CT', + 'postalCode' => '06514', + ], + ] + ); + + $this->assertPropertyEquals('jobTitle', 'tester'); + + $this->assertPropertyEquals('parent', + [ + '@type' => 'Person', + 'name' => 'daddy' + ]); + + $this->assertPropertyEquals('telephone', '+330102030405'); + } + +} \ No newline at end of file diff --git a/tests/ContextTypes/PlaceTest.php b/tests/ContextTypes/PlaceTest.php new file mode 100644 index 0000000..37e5914 --- /dev/null +++ b/tests/ContextTypes/PlaceTest.php @@ -0,0 +1,46 @@ + 'Fluff Hut', + 'address' => [ + 'streetAddress' => '112 Apple St.', + 'addressLocality' => 'Hamden', + 'addressRegion' => 'CT', + 'postalCode' => '06514', + ], + 'review' => [ + 'reviewBody' => 'beautifull place', + 'reviewRating' => 10, + ], + ]; + + public function test_should_have_properties() { + + $this->assertPropertyEquals('name', 'Fluff Hut'); + + $this->assertPropertyEquals('address', + [ + '@type' => 'PostalAddress', + 'streetAddress' => '112 Apple St.', + 'addressLocality' => 'Hamden', + 'addressRegion' => 'CT', + 'postalCode' => '06514', + ]); + + $this->assertPropertyEquals('review', + [ + '@type' => 'Review', + 'reviewBody' => 'beautifull place', + 'reviewRating' => 10, + ]); + } + +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index b5eb5a8..b1ce5af 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,6 +21,15 @@ protected function make() return new $this->class($this->attributes); } + protected function assertPropertyEquals($property, $expectedValue) + { + $context = $this->make(); + + $assertMessage = 'asserting \''.$this->class.'\' property \''.$property.'\''; + $this->assertEquals($expectedValue, $context->getProperty($property), $assertMessage); + } + + protected function makeJsonLdContext() { return \JsonLd\Context::create($this->class, $this->attributes); From 55fd43dbbcd23ec25d1830e24612d0bf7ad6300e Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 15:49:50 -0400 Subject: [PATCH 03/10] Update AbstractContext.php --- src/ContextTypes/AbstractContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ContextTypes/AbstractContext.php b/src/ContextTypes/AbstractContext.php index 790bc74..e958c5c 100644 --- a/src/ContextTypes/AbstractContext.php +++ b/src/ContextTypes/AbstractContext.php @@ -168,7 +168,7 @@ protected function setProperty($key, $property, $value = null) } // Map properties to object - if ($property != null && is_array($property) && is_array($value)) { + if ($property !== null && is_array($property) && is_array($value)) { return $this->properties[$key] = $this->mapProperty($property, $value); } From a012169d33a9d07c56233c7b94792323539cf92c Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 15:59:16 -0400 Subject: [PATCH 04/10] Update Article.php Add back a few missing properties --- src/ContextTypes/Article.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ContextTypes/Article.php b/src/ContextTypes/Article.php index 019c445..b834e94 100644 --- a/src/ContextTypes/Article.php +++ b/src/ContextTypes/Article.php @@ -11,12 +11,15 @@ class Article extends CreativeWork * @var array */ private $extendedStructure = [ + 'description' => null, + 'keywords' => null, 'articleBody' => null, 'articleSection' => null, 'pageEnd' => null, 'pageStart' => null, 'pagination' => null, - 'wordCount' => null + 'wordCount' => null, + 'mainEntityOfPage' => WebPage::class, ]; /** From 71eb4a9d6c51a41add347b8c24e30d5f86fe2f81 Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:01:39 -0400 Subject: [PATCH 05/10] Update Article.php Ugh sorry, you had this correct --- src/ContextTypes/Article.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ContextTypes/Article.php b/src/ContextTypes/Article.php index b834e94..b25a276 100644 --- a/src/ContextTypes/Article.php +++ b/src/ContextTypes/Article.php @@ -11,8 +11,6 @@ class Article extends CreativeWork * @var array */ private $extendedStructure = [ - 'description' => null, - 'keywords' => null, 'articleBody' => null, 'articleSection' => null, 'pageEnd' => null, From f3b2804ee39922c8fdcda5af11adc00f1c729d57 Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:02:45 -0400 Subject: [PATCH 06/10] Update CreativeWork.php Linting --- src/ContextTypes/CreativeWork.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ContextTypes/CreativeWork.php b/src/ContextTypes/CreativeWork.php index 03d792f..660ce1a 100644 --- a/src/ContextTypes/CreativeWork.php +++ b/src/ContextTypes/CreativeWork.php @@ -29,12 +29,9 @@ class CreativeWork extends Thing 'review' => Review::class, 'text' => null, 'thumbnailUrl' => null, - 'video' => VideoObject::class + 'video' => VideoObject::class, ]; - - - /** * Constructor. Merges extendedStructure up * @@ -43,7 +40,9 @@ class CreativeWork extends Thing */ public function __construct(array $attributes, array $extendedStructure = []) { - parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + parent::__construct( + $attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure) + ); } /** @@ -65,7 +64,7 @@ protected function setTextAttribute($txt) */ protected function setCommentAttribute($items) { - if (!is_array($items)) { + if (is_array($items) === false) { return $items; } @@ -73,5 +72,4 @@ protected function setCommentAttribute($items) return $this->getNestedContext(Comment::class, $item); }, $items); } - -} \ No newline at end of file +} From 05c9392e1de698debcf51eb14b6c5d82c76107cb Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:03:09 -0400 Subject: [PATCH 07/10] Update Person.php Linting --- src/ContextTypes/Person.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ContextTypes/Person.php b/src/ContextTypes/Person.php index 608b95f..76b0858 100644 --- a/src/ContextTypes/Person.php +++ b/src/ContextTypes/Person.php @@ -34,7 +34,7 @@ class Person extends Thing 'jobTitle' => null, 'parent' => Person::class, 'telephone' => null, - 'workLocation' => Place::class + 'workLocation' => Place::class, ]; /** @@ -56,9 +56,10 @@ public function __construct(array $attributes, array $extendedStructure = []) */ protected function setAddressAttribute($items) { - if (!is_array($items)) { + if (is_array($items) === false) { return $items; } + return $this->getNestedContext(PostalAddress::class, $items); } -} \ No newline at end of file +} From bbaad1ee6482e7047905dd2e19a5d7684c1d72ce Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:03:41 -0400 Subject: [PATCH 08/10] Update Sculpture.php Linting --- src/ContextTypes/Sculpture.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ContextTypes/Sculpture.php b/src/ContextTypes/Sculpture.php index 464294f..49dc38f 100644 --- a/src/ContextTypes/Sculpture.php +++ b/src/ContextTypes/Sculpture.php @@ -2,14 +2,14 @@ namespace JsonLd\ContextTypes; -class Sculpture extends CreativeWork { +class Sculpture extends CreativeWork +{ /** * Property structure. * * @var array */ - private $extendedStructure = [ - ]; + private $extendedStructure = []; /** * Constructor. Merges extendedStructure up @@ -19,6 +19,8 @@ class Sculpture extends CreativeWork { */ public function __construct(array $attributes, array $extendedStructure = []) { - parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + parent::__construct( + $attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure) + ); } } From 2f8af12e32ea64dd01c04ccc8115065fbd507872 Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:04:05 -0400 Subject: [PATCH 09/10] Linting --- src/ContextTypes/Thing.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ContextTypes/Thing.php b/src/ContextTypes/Thing.php index 27f3c03..3e8935b 100644 --- a/src/ContextTypes/Thing.php +++ b/src/ContextTypes/Thing.php @@ -17,7 +17,7 @@ class Thing extends AbstractContext 'mainEntityOfPage' => WebPage::class, 'name' => null, 'sameAs' => null, - 'url' => null + 'url' => null, ]; /** @@ -43,4 +43,4 @@ protected function setTypeAttribute($type) // TODO: Add type validation return $type; } -} \ No newline at end of file +} From 25f5953ad01a2d2706bf00d32629e18b0bee8dbb Mon Sep 17 00:00:00 2001 From: Daniel Stainback Date: Fri, 12 Oct 2018 16:05:01 -0400 Subject: [PATCH 10/10] Linting --- src/ContextTypes/Comment.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ContextTypes/Comment.php b/src/ContextTypes/Comment.php index 669d4e3..51565ff 100644 --- a/src/ContextTypes/Comment.php +++ b/src/ContextTypes/Comment.php @@ -2,7 +2,8 @@ namespace JsonLd\ContextTypes; -class Comment extends CreativeWork { +class Comment extends CreativeWork +{ /** * Property structure. * reference: https://schema.org/Comment (alphabetical order) @@ -11,10 +12,9 @@ class Comment extends CreativeWork { */ private $extendedStructure = [ 'downvoteCount' => null, - 'upvoteCount' => null + 'upvoteCount' => null, ]; - /** * Constructor. Merges extendedStructure up * @@ -23,6 +23,8 @@ class Comment extends CreativeWork { */ public function __construct(array $attributes, array $extendedStructure = []) { - parent::__construct($attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)); + parent::__construct( + $attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure) + ); } }