1 | <?php |
||
2 | |||
3 | namespace SilverStripe\VersionedAdmin\Tests\ArchiveAdminTest; |
||
4 | |||
5 | use SilverStripe\Dev\TestOnly; |
||
6 | use SilverStripe\ORM\DataObject; |
||
7 | use SilverStripe\Versioned\Versioned; |
||
8 | use SilverStripe\VersionedAdmin\Interfaces\ArchiveViewProvider; |
||
9 | |||
10 | class ViewProviderVersionedObject extends DataObject implements ArchiveViewProvider, TestOnly |
||
11 | { |
||
12 | private static $table_name = 'Test_ViewProviderVersionedObject'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
13 | |||
14 | private static $extensions = [ |
||
0 ignored issues
–
show
|
|||
15 | Versioned::class, |
||
16 | ]; |
||
17 | |||
18 | public function getArchiveFieldClass() |
||
19 | { |
||
20 | return ViewProviderVersionedObject::class; |
||
0 ignored issues
–
show
The expression
return SilverStripe\Vers...rVersionedObject::class returns the type string which is incompatible with the return type mandated by SilverStripe\VersionedAd...:getArchiveFieldClass() of array .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||
21 | } |
||
22 | public function getArchiveField() |
||
23 | { |
||
24 | return null; |
||
25 | } |
||
26 | public function isArchiveFieldEnabled() |
||
27 | { |
||
28 | return true; |
||
29 | } |
||
30 | } |
||
31 |