Skip to content

Commit 6048285

Browse files
committed
v2: Silverstripe 5 support
1 parent 2d4f4a9 commit 6048285

File tree

8 files changed

+16
-39
lines changed

8 files changed

+16
-39
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ on:
66

77
jobs:
88
ci:
9-
uses: silverstripe/github-actions-ci-cd/.github/workflows/ci.yml@v0.1
9+
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
"issues": "https://github.com/chrispenny/silverstripe-dataobject-to-fixture/issues"
1717
},
1818
"require": {
19-
"php": "^7.4 || ^8.0",
20-
"silverstripe/vendor-plugin": "^1.0",
21-
"silverstripe/framework": "^4.8",
22-
"silverstripe/cms": "^4.8"
19+
"php": "^8.1",
20+
"silverstripe/framework": "^5",
21+
"silverstripe/cms": "^5"
2322
},
2423
"require-dev": {
25-
"phpunit/phpunit": "^9.5",
24+
"silverstripe/recipe-testing": "^3",
2625
"slevomat/coding-standard": "^8"
2726
},
2827
"autoload": {

phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
<!-- Complexity check often fails at getCMSFields(). -->
143143
<!-- Each team/project can decide if they'd prefer to just tweak the complexity level rather than exclude this rule -->
144144
<exclude name="SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh"/>
145+
<!-- Don't require alphabetical array keys -->
146+
<exclude name="SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder"/>
147+
<exclude name="SlevomatCodingStandard.Classes.RequireSelfReference.RequiredSelfReference"/>
145148
</rule>
146149

147150
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">

src/Manifest/FixtureManifest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public function getGroupByClassName(string $className): ?Group
3131
return $this->groups[$className];
3232
}
3333

34-
/**
35-
* @param string|int $id
36-
*/
37-
public function getRecordByClassNameId(string $className, $id): ?Record
34+
public function getRecordByClassNameId(string $className, string|int $id): ?Record
3835
{
3936
$group = $this->getGroupByClassName($className);
4037

src/ORM/Group.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ class Group
99

1010
use Injectable;
1111

12-
private ?string $className;
13-
1412
/**
1513
* @var array|Record[]
1614
*/
1715
private array $records = [];
1816

19-
public function __construct(string $className)
17+
public function __construct(private readonly string $className)
2018
{
21-
$this->className = $className;
2219
}
2320

2421
public function getClassName(): string
@@ -34,10 +31,7 @@ public function getRecords(): array
3431
return $this->records;
3532
}
3633

37-
/**
38-
* @param mixed $id
39-
*/
40-
public function getRecordById($id): ?Record
34+
public function getRecordById(string|int $id): ?Record
4135
{
4236
if (!array_key_exists($id, $this->records)) {
4337
return null;

src/ORM/Record.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@ class Record
99

1010
use Injectable;
1111

12-
/**
13-
* @var int|string|null
14-
*/
15-
private $id;
16-
1712
private array $fields = [];
1813

19-
/**
20-
* @param mixed $id
21-
*/
22-
public function __construct($id)
14+
public function __construct(private readonly string|int $id)
2315
{
24-
$this->id = $id;
2516
}
2617

27-
/**
28-
* @return int|string|null
29-
*/
30-
public function getId()
18+
public function getId(): string|int
3119
{
3220
return $this->id;
3321
}
@@ -37,10 +25,7 @@ public function getFields(): array
3725
return $this->fields;
3826
}
3927

40-
/**
41-
* @param mixed $value
42-
*/
43-
public function addFieldValue(string $fieldName, $value): Record
28+
public function addFieldValue(string $fieldName, mixed $value): Record
4429
{
4530
$this->fields[$fieldName] = $value;
4631

src/Service/FixtureService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,9 @@ private function findOrCreateGroupByClassName(string $className): Group
545545
}
546546

547547
/**
548-
* @param string|int $id
549548
* @throws Exception
550549
*/
551-
private function findOrCreateRecordByClassNameId(string $className, $id): Record
550+
private function findOrCreateRecordByClassNameId(string $className, string|int $id): Record
552551
{
553552
$group = $this->findOrCreateGroupByClassName($className);
554553

src/Task/GenerateFixtureFromDataObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GenerateFixtureFromDataObject extends BuildTask
2222

2323
protected $description = 'Generate a text fixture from a DataObject in your Database'; // phpcs:ignore
2424

25-
private static $segment = 'generate-fixture-from-dataobject'; // phpcs:ignore
25+
private static string $segment = 'generate-fixture-from-dataobject'; // phpcs:ignore
2626

2727
private ?int $previousExecution = null;
2828

0 commit comments

Comments
 (0)