Skip to content

Commit a724f50

Browse files
authored
Merge pull request #3 from nswdpc/feat-ci-files
Update dev requirements
2 parents 0facea4 + e3889f5 commit a724f50

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
jobs:
77
Silverstripe:
88
name: 'Silverstripe (bundle)'
9-
uses: nswdpc/ci-files/.github/workflows/silverstripe.yml@1.1.1
9+
uses: nswdpc/ci-files/.github/workflows/silverstripe_53_83.yml@v-4
1010
PHPStan:
1111
name: 'PHPStan (analyse)'
12-
uses: nswdpc/ci-files/.github/workflows/phpstan.silverstripe.yml@1.1.1
13-
needs: Silverstripe
12+
uses: nswdpc/ci-files/.github/workflows/phpstan.silverstripe_83.yml@v-4
13+
needs: Silverstripe

composer.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@
2626
"silverstripe/asset-admin": "^2"
2727
},
2828
"require-dev": {
29-
"cambis/silverstripe-rector": "^0.5.1",
29+
"cambis/silverstripe-rector": "^2",
30+
"cambis/silverstan": "^2",
31+
"phpstan/phpstan": "^2",
32+
"phpstan/phpstan-phpunit": "^2",
33+
"rector/rector": "^2",
3034
"phpunit/phpunit": "^9.5",
31-
"syntro/silverstripe-phpstan": "^5",
32-
"nswdpc/ci-files": "^1"
35+
"nswdpc/ci-files": "dev-v-4",
36+
"friendsofphp/php-cs-fixer": "^3"
3337
},
34-
"repositories": [
35-
{
36-
"type": "git",
37-
"url": "https://github.com/nswdpc/ci-files.git"
38-
}
39-
],
4038
"autoload": {
4139
"psr-4": {
4240
"NSWDPC\\Embed\\": "src/",
@@ -50,5 +48,11 @@
5048
"silverstripe/vendor-plugin": true,
5149
"phpstan/extension-installer": true
5250
}
51+
},
52+
"scripts": {
53+
"phpstan-analyse": "./vendor/bin/phpstan analyse --ansi --no-progress --no-interaction --configuration vendor/nswdpc/ci-files/phpstan/.phpstan.silverstripe.neon src/ tests/",
54+
"rector-dryrun": "./vendor/bin/rector process --dry-run --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
55+
"rector-process": "./vendor/bin/rector process --no-diffs --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
56+
"phpcsfixer-fix": "./vendor/bin/php-cs-fixer fix --ansi --no-interaction --config vendor/nswdpc/ci-files/php-cs-fixer/.php-cs-fixer.php src/ tests/"
5357
}
5458
}

src/Extensions/Embeddable.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@
88
use NSWDPC\Embed\Services\Logger;
99
use SilverStripe\Assets\Image;
1010
use SilverStripe\Assets\Folder;
11-
use SilverStripe\Assets\File;
12-
use SilverStripe\Assets\Storage\AssetStore;
1311
use SilverStripe\Forms\CheckboxField;
1412
use SilverStripe\Forms\CompositeField;
1513
use SilverStripe\Forms\FieldList;
1614
use SilverStripe\Forms\TextField;
1715
use SilverStripe\Forms\TextareaField;
1816
use SilverStripe\Forms\ReadonlyField;
1917
use SilverStripe\AssetAdmin\Forms\UploadField;
20-
use SilverStripe\Core\Convert;
2118
use SilverStripe\ORM\DataObject;
22-
use SilverStripe\ORM\ValidationException;
23-
use SilverStripe\ORM\ValidationResult;
2419
use SilverStripe\ORM\DataExtension;
2520
use SilverStripe\ORM\FieldType\DBField;
2621
use SilverStripe\ORM\FieldType\DBHTMLText;
@@ -29,6 +24,18 @@
2924

3025
/**
3126
* Embeddable extension for Silverstripe DataObject
27+
* @property ?string $EmbedTitle
28+
* @property ?string $EmbedType
29+
* @property ?string $EmbedSourceURL
30+
* @property ?string $EmbedSourceImageURL
31+
* @property ?string $EmbedHTML
32+
* @property ?string $EmbedWidth
33+
* @property ?string $EmbedHeight
34+
* @property ?string $EmbedAspectRatio
35+
* @property ?string $EmbedDescription
36+
* @property int $EmbedImageID
37+
* @method \SilverStripe\Assets\Image EmbedImage()
38+
* @extends \SilverStripe\ORM\DataExtension<(\NSWDPC\Embed\Models\Embed & static)>
3239
*/
3340
class Embeddable extends DataExtension
3441
{
@@ -168,16 +175,16 @@ public function updateCMSFields(FieldList $fields)
168175
public function getExtractor(): Extractor
169176
{
170177
$sourceURL = $this->getOwner()->EmbedSourceURL ?? '';
171-
if($sourceURL === '') {
178+
if ($sourceURL === '') {
172179
throw new \RuntimeException(_t(self::class . '.EMPTY_SOURCE_URL', 'Source URL is empty'));
173180
}
174181

175-
$parts = parse_url($sourceURL);
176-
if(!isset($parts['scheme'])) {
182+
$parts = parse_url((string) $sourceURL);
183+
if (!isset($parts['scheme'])) {
177184
throw new \RuntimeException(_t(self::class . '.EMPTY_SOURCE_URL_SCHEME', 'Source URL has no scheme'));
178185
}
179186

180-
if(!isset($parts['host'])) {
187+
if (!isset($parts['host'])) {
181188
throw new \RuntimeException(_t(self::class . '.EMPTY_SOURCE_URL_HOST', 'Source URL has no host'));
182189
}
183190

@@ -214,13 +221,13 @@ protected function writeFromEmbed(bool $force = false): bool
214221
$urlChanged = $owner->isChanged('EmbedSourceURL', DataObject::CHANGE_VALUE);
215222
if ($force || $urlChanged) {
216223
// embed data from updated source URL
217-
$owner->EmbedHTML = $extractor->code->html;
224+
$owner->EmbedHTML = $extractor->code->html ?? '';
218225
$oembed = $this->getOEmbed($extractor);
219226
// save type for oembed, if it exists
220227
$owner->EmbedType = strtolower($oembed->get('type') ?? '');
221-
$owner->EmbedWidth = $extractor->code->width;
222-
$owner->EmbedHeight = $extractor->code->height;
223-
$owner->EmbedAspectRatio = $extractor->code->ratio;
228+
$owner->EmbedWidth = $extractor->code->width ?? '';
229+
$owner->EmbedHeight = $extractor->code->height ?? '';
230+
$owner->EmbedAspectRatio = $extractor->code->ratio ?? '';
224231
// allow some customisation from the owner object prior to write, when the source url has changed
225232
$owner->extend('onEmbedSourceChange', $embed);
226233
}
@@ -252,7 +259,7 @@ public function onBeforeWrite()
252259
public function getAllowedEmbedTypes(): array
253260
{
254261
$allowedEmbedTypes = $this->getOwner()->config()->get('allowed_embed_types');
255-
if(!is_array($allowedEmbedTypes)) {
262+
if (!is_array($allowedEmbedTypes)) {
256263
$allowedEmbedTypes = [];
257264
}
258265

@@ -323,7 +330,7 @@ public function getEmbed(): DBHTMLText
323330
$type = (string)$owner->EmbedType;
324331
$template = $this->getEmbedTemplate();
325332
$templates = [];
326-
if($type !== '') {
333+
if ($type !== '') {
327334
$templates[] = $template . '_' . $type;
328335
}
329336

@@ -350,7 +357,7 @@ public function getEmbedByType(): DBHTMLText
350357
$height = $owner->EmbedHeight;
351358
$html = '';
352359
$attributes = [];
353-
if($cssClasses !== '') {
360+
if ($cssClasses !== '') {
354361
$attributes['class'] = $cssClasses;
355362
}
356363

@@ -377,6 +384,7 @@ public function getEmbedByType(): DBHTMLText
377384
break;
378385
}
379386

380-
return DBField::create_field(DBHTMLText::class, $html);
387+
// @phpstan-ignore return.type
388+
return DBField::create_field('HTMLFragment', $html);
381389
}
382390
}

src/Models/Embed.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* Embed
13+
* @mixin \NSWDPC\Embed\Extensions\Embeddable
1314
**/
1415
class Embed extends DataObject
1516
{
@@ -57,6 +58,7 @@ class Embed extends DataObject
5758
/**
5859
* @inheritdoc
5960
*/
61+
#[\Override]
6062
public function getCMSFields()
6163
{
6264
$fields = FieldList::create(
@@ -73,6 +75,7 @@ public function getCMSFields()
7375
/**
7476
* @inheritdoc
7577
*/
78+
#[\Override]
7679
public function getTitle()
7780
{
7881
return $this->EmbedTitle;
@@ -102,7 +105,7 @@ public function getClass(): string
102105
* Renders an HTML anchor tag for this link
103106
* See Embeddable::getEmbed()
104107
*/
105-
public function forTemplate()
108+
public function forTemplate(): \SilverStripe\ORM\FieldType\DBHTMLText
106109
{
107110
return $this->getEmbed();
108111
}

src/Models/Video.php

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

33
namespace NSWDPC\Embed\Models;
44

5-
use NSWDPC\Embed\Models\Embed;
6-
75
/**
86
* Video - video specific embed
97
**/

0 commit comments

Comments
 (0)