Skip to content

Commit ecdb9a8

Browse files
committed
Ran Pint
1 parent 8ba81db commit ecdb9a8

File tree

8 files changed

+45
-40
lines changed

8 files changed

+45
-40
lines changed

src/Fieldtypes/AvailableVariablesFieldtype.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ protected function getAvailableVariables(): array
3131
{
3232
return [
3333
'site' => [
34-
['name' => 'site:name', 'description' => 'Site Name'],
35-
['name' => 'site:url', 'description' => 'Site URL'],
36-
],
34+
['name' => 'site:name', 'description' => 'Site Name'],
35+
['name' => 'site:url', 'description' => 'Site URL'],
36+
],
3737
'globals' => $this->getGlobalVariables(),
3838
'entry' => $this->getEntryFields(),
3939
'term' => $this->getTermFields(),
@@ -66,15 +66,15 @@ protected function getEntryFields(): array
6666
return [];
6767
}
6868

69-
$fields = collect($dataTemplate?->use_for_collection?->entryBlueprints()?->reduce(function($carry, $blueprint) {
69+
$fields = collect($dataTemplate?->use_for_collection?->entryBlueprints()?->reduce(function ($carry, $blueprint) {
7070
return array_merge($carry, $blueprint->fields()->items()->toArray());
7171
}, []) ?? []);
7272

73-
if(class_exists(OnPageSeoBlueprint::class)) {
73+
if (class_exists(OnPageSeoBlueprint::class)) {
7474
$fields = $fields->merge(OnPageSeoBlueprint::requestBlueprint()->fields()?->items());
7575
}
7676

77-
if (!$fields) {
77+
if (! $fields) {
7878
return [];
7979
}
8080

@@ -83,9 +83,9 @@ protected function getEntryFields(): array
8383
$collectionFields = $fields->map(function ($field) {
8484
return $this->setFieldData($field);
8585
})
86-
->filter()
87-
->values()
88-
->all();
86+
->filter()
87+
->values()
88+
->all();
8989

9090
return array_merge($baseFields, $collectionFields);
9191
}
@@ -98,15 +98,15 @@ protected function getTermFields(): array
9898
return [];
9999
}
100100

101-
$fields = collect($dataTemplate?->use_for_taxonomy?->termBlueprints()?->reduce(function($carry, $blueprint) {
101+
$fields = collect($dataTemplate?->use_for_taxonomy?->termBlueprints()?->reduce(function ($carry, $blueprint) {
102102
return array_merge($carry, $blueprint->fields()->items()->toArray());
103103
}, []) ?? []);
104104

105-
if(class_exists(OnPageSeoBlueprint::class)) {
105+
if (class_exists(OnPageSeoBlueprint::class)) {
106106
$fields = $fields->merge(OnPageSeoBlueprint::requestBlueprint()->fields()?->items());
107107
}
108108

109-
if (!$fields) {
109+
if (! $fields) {
110110
return [];
111111
}
112112

@@ -115,9 +115,9 @@ protected function getTermFields(): array
115115
$collectionFields = $fields->map(function ($field) {
116116
return $this->setFieldData($field);
117117
})
118-
->filter()
119-
->values()
120-
->all();
118+
->filter()
119+
->values()
120+
->all();
121121

122122
return array_merge($baseFields, $collectionFields);
123123
}
@@ -132,8 +132,9 @@ protected function getGlobalVariables(): array
132132

133133
if ($fields) {
134134
$globalVariables = $fields->items()->map(function ($field) use ($globalSet) {
135-
$name = ($globalSet->handle() . ':' . ($field['handle'] ?? ''));
135+
$name = ($globalSet->handle().':'.($field['handle'] ?? ''));
136136
$description = ($field['field']['display'] ?? ($field['handle'] ?? ''));
137+
137138
return $this->setFieldData($field, $name, $description);
138139
})->values()->all();
139140
}
@@ -146,27 +147,28 @@ protected function getGlobalVariables(): array
146147

147148
protected function getCollectionVariables(string $collectionHandle, array $field): array
148149
{
149-
if(!$collectionHandle || $collectionHandle === 'structured_data_templates') {
150+
if (! $collectionHandle || $collectionHandle === 'structured_data_templates') {
150151
return [];
151152
}
152153

153154
return Collection::find($collectionHandle)?->entryBlueprints()?->first()?->fields()?->items()?->map(function ($entryField) use ($field) {
154-
$name = ($field['handle'] . ':' . ($entryField['handle'] ?? ''));
155-
$description = (($field['field']['display'] ?? '') . ': ' . ($entryField['field']['display'] ?? ($entryField['handle'] ?? '')));
155+
$name = ($field['handle'].':'.($entryField['handle'] ?? ''));
156+
$description = (($field['field']['display'] ?? '').': '.($entryField['field']['display'] ?? ($entryField['handle'] ?? '')));
157+
156158
return $this->setFieldData($entryField, $name, $description, false);
157159
})->filter()->values()->all();
158160
}
159161

160162
protected function setFieldData(array $field, ?string $name = null, ?string $description = null, bool $recursive = true): ?array
161163
{
162-
if(!($field['handle'] ?? false) || $field['handle'] === 'parent' || !($field['field']['type'] ?? false) || !$this->fieldTypeIsEligible($field['field']['type'])) {
164+
if (! ($field['handle'] ?? false) || $field['handle'] === 'parent' || ! ($field['field']['type'] ?? false) || ! $this->fieldTypeIsEligible($field['field']['type'])) {
163165
return null;
164166
}
165167

166168
$children = [];
167169

168-
if($field['field']['type'] === 'entries' && $recursive) {
169-
if(!isset($field['field']['collections'][0])) {
170+
if ($field['field']['type'] === 'entries' && $recursive) {
171+
if (! isset($field['field']['collections'][0])) {
170172
return null;
171173
}
172174

@@ -176,7 +178,7 @@ protected function setFieldData(array $field, ?string $name = null, ?string $des
176178
return [
177179
'name' => $name ?? $field['handle'],
178180
'description' => $description ?? ($field['field']['display'] ?? $field['handle']),
179-
'children' => $children
181+
'children' => $children,
180182
];
181183
}
182184
}

src/Fieldtypes/StructuredDataBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Illuminate\Support\Collection;
66
use Statamic\Facades\Site;
7-
use Statamic\Fields\Fieldtype;
87
use Statamic\Facades\Taxonomy;
8+
use Statamic\Fields\Fieldtype;
99

1010
class StructuredDataBuilder extends Fieldtype
1111
{

src/Http/Controllers/StructuredDataController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getTemplates(Request $request)
5555

5656
$structuredData = $entry->schema_data;
5757

58-
if (!$structuredData) {
58+
if (! $structuredData) {
5959
return null;
6060
}
6161

@@ -91,7 +91,7 @@ public function getAvailableVariables(Request $request)
9191
'entry' => [],
9292
];
9393

94-
if (!$entry) {
94+
if (! $entry) {
9595
return response()->json($variables);
9696
}
9797

src/Http/Middleware/InjectStructuredData.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Response;
88
use Justbetter\StatamicStructuredData\Services\StructuredDataService;
9-
use Statamic\Facades\Entry as EntryFacade;
109
use Statamic\Entries\Entry;
10+
use Statamic\Facades\Entry as EntryFacade;
1111
use Statamic\Facades\Site;
12+
use Statamic\Facades\Term;
1213
use Statamic\Facades\URL;
1314
use Statamic\Structures\Page;
14-
use Statamic\Facades\Term;
1515
use Statamic\Taxonomies\LocalizedTerm;
1616

1717
class InjectStructuredData
@@ -76,7 +76,7 @@ protected function handleScripts($response, $item)
7676
{
7777
$scripts = $this->structuredDataService->getJsonLdScripts($item);
7878

79-
if (!$scripts ?? false) {
79+
if (! $scripts ?? false) {
8080
return $response;
8181
}
8282

@@ -101,12 +101,14 @@ protected function shouldInject($response): bool
101101
protected function getCurrentEntry(): Page|Entry|null
102102
{
103103
$url = URL::getCurrent();
104+
104105
return EntryFacade::findByUri($url, Site::current()->handle());
105106
}
106107

107-
protected function getCurrentTerm(): LocalizedTerm|null
108+
protected function getCurrentTerm(): ?LocalizedTerm
108109
{
109110
$url = URL::getCurrent();
111+
110112
return Term::findByUri($url, Site::current()->handle());
111113
}
112114
}

src/Listeners/AddStructuredDataTab.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Statamic\Events\EntryBlueprintFound;
66
use Statamic\Events\TermBlueprintFound;
7-
use Statamic\Facades\Collection;
87
use Statamic\Fields\Blueprint;
98

109
class AddStructuredDataTab
@@ -15,9 +14,11 @@ public function handle(EntryBlueprintFound|TermBlueprintFound $event): void
1514

1615
if ($event instanceof EntryBlueprintFound && str_contains($blueprint->namespace(), 'collections')) {
1716
$this->handleCollectionBlueprintFound($blueprint);
17+
1818
return;
1919
} elseif ($event instanceof TermBlueprintFound && str_contains($blueprint->namespace(), 'taxonomies')) {
2020
$this->handleTaxonomyBlueprintFound($blueprint);
21+
2122
return;
2223
}
2324
}
@@ -26,7 +27,7 @@ public function handleCollectionBlueprintFound(Blueprint $blueprint): void
2627
{
2728
$handle = str_replace('collections.', '', $blueprint->namespace());
2829
$enabledCollections = config('justbetter.structured-data.collections', []);
29-
30+
3031
if (! in_array($handle, $enabledCollections)) {
3132
return;
3233
}

src/Parser/StructuredDataParser.php

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

33
namespace Justbetter\StatamicStructuredData\Parser;
44

5+
use Justbetter\StatamicStructuredData\Services\StructuredDataService;
56
use Statamic\Facades\Site;
67
use Statamic\Facades\Term;
78
use Statamic\View\Antlers\Antlers;
8-
use Justbetter\StatamicStructuredData\Services\StructuredDataService;
99

1010
class StructuredDataParser
1111
{
@@ -65,7 +65,7 @@ protected function getObjectData($objectSlug): array
6565
->where('slug', $objectSlug)
6666
->first();
6767

68-
if (! $dataObject || !$dataObject->object_data) {
68+
if (! $dataObject || ! $dataObject->object_data) {
6969
return [];
7070
}
7171

src/ServiceProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
use Illuminate\Support\Facades\File;
77
use Justbetter\StatamicStructuredData\Fieldtypes\AvailableVariablesFieldtype;
88
use Justbetter\StatamicStructuredData\Fieldtypes\StructuredDataBuilder;
9-
use Justbetter\StatamicStructuredData\Fieldtypes\StructuredDataPreview;
109
use Justbetter\StatamicStructuredData\Fieldtypes\StructuredDataObjectBuilder;
10+
use Justbetter\StatamicStructuredData\Fieldtypes\StructuredDataPreview;
1111
use Justbetter\StatamicStructuredData\Http\Middleware\InjectStructuredData;
1212
use Justbetter\StatamicStructuredData\Listeners\AddStructuredDataTab;
1313
use Statamic\Events\EntryBlueprintFound;
1414
use Statamic\Events\TermBlueprintFound;
1515
use Statamic\Facades\Blueprint;
1616
use Statamic\Facades\Collection;
1717
use Statamic\Facades\Site;
18+
use Statamic\Facades\Taxonomy;
1819
use Statamic\Providers\AddonServiceProvider;
1920
use Symfony\Component\Yaml\Yaml;
20-
use Statamic\Facades\Taxonomy;
2121

2222
class ServiceProvider extends AddonServiceProvider
2323
{
@@ -60,7 +60,7 @@ public function bootEvents()
6060

6161
public function bootCollections()
6262
{
63-
if($this->app->runningInConsole() || Collection::find('structured_data_templates')) {
63+
if ($this->app->runningInConsole() || Collection::find('structured_data_templates')) {
6464
return $this;
6565
}
6666

@@ -82,7 +82,7 @@ public function bootCollections()
8282

8383
public function bootTaxonomies()
8484
{
85-
if($this->app->runningInConsole() || Taxonomy::find('structured_data_objects')) {
85+
if ($this->app->runningInConsole() || Taxonomy::find('structured_data_objects')) {
8686
return $this;
8787
}
8888

src/Services/StructuredDataService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Justbetter\StatamicStructuredData\Parser\StructuredDataParser;
66
use Statamic\Contracts\Entries\Entry as EntryContract;
77
use Statamic\Facades\Entry as EntryFacade;
8-
use Statamic\Taxonomies\LocalizedTerm;
98
use Statamic\Structures\Page;
9+
use Statamic\Taxonomies\LocalizedTerm;
1010

1111
class StructuredDataService
1212
{
@@ -21,7 +21,7 @@ public function getJsonLdScripts($item): array
2121
{
2222
$templates = $this->getTemplates($item);
2323

24-
if (!($templates ?? false)) {
24+
if (! $templates) {
2525
return [];
2626
}
2727

0 commit comments

Comments
 (0)