1 | <?php |
||
21 | class CitationTextChangeUpdateJobDispatcher { |
||
22 | |||
23 | /** |
||
24 | * @var Store |
||
25 | */ |
||
26 | private $store; |
||
27 | |||
28 | /** |
||
29 | * @var ReferenceBacklinksLookup |
||
30 | */ |
||
31 | private $referenceBacklinksLookup; |
||
32 | |||
33 | /** |
||
34 | * @var boolean |
||
35 | */ |
||
36 | private $enabledUpdateJobState = true; |
||
37 | |||
38 | /** |
||
39 | * @since 1.0 |
||
40 | * |
||
41 | * @param Store $store |
||
42 | * @param ReferenceBacklinksLookup $referenceBacklinksLookup |
||
43 | */ |
||
44 | 19 | public function __construct( Store $store, ReferenceBacklinksLookup $referenceBacklinksLookup ) { |
|
48 | |||
49 | /** |
||
50 | * @since 1.0 |
||
51 | * |
||
52 | * @param boolean $enabledUpdateJobState |
||
53 | */ |
||
54 | 15 | public function setEnabledUpdateJobState( $enabledUpdateJobState ) { |
|
57 | |||
58 | /** |
||
59 | * @since 1.0 |
||
60 | * |
||
61 | * @param DIWikiPage $subject |
||
62 | * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator |
||
63 | * |
||
64 | * @return boolean |
||
65 | */ |
||
66 | 18 | public function dispatchUpdateJobFor( DIWikiPage $subject, CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator ) { |
|
67 | |||
68 | 18 | if ( !$this->enabledUpdateJobState ) { |
|
69 | 15 | return false; |
|
70 | } |
||
71 | |||
72 | 3 | $tableName = $this->store->getPropertyTableInfoFetcher()->findTableIdForProperty( |
|
|
|||
73 | 3 | new DIProperty( PropertyRegistry::SCI_CITE_TEXT ) |
|
74 | 3 | ); |
|
75 | |||
76 | 3 | $subjectIdList = $this->getSubjectListFrom( |
|
77 | 3 | $compositePropertyTableDiffIterator->getOrderedDiffByTable( $tableName ) |
|
78 | 3 | ); |
|
79 | |||
80 | 3 | if ( ( $jobList = $this->getDispatchableTargetList( $subjectIdList ) ) === [] ) { |
|
81 | 1 | return false; |
|
82 | } |
||
83 | |||
84 | 2 | $updateDispatcherJob = ApplicationFactory::getInstance()->newJobFactory()->newUpdateDispatcherJob( |
|
85 | 2 | $subject->getTitle(), |
|
86 | [ |
||
87 | 'job-list' => $jobList |
||
88 | 2 | ] |
|
89 | 2 | ); |
|
90 | |||
91 | 2 | $updateDispatcherJob->insert(); |
|
92 | |||
93 | 2 | return true; |
|
94 | } |
||
95 | |||
96 | 3 | private function getSubjectListFrom( array $orderedDiff ) { |
|
126 | |||
127 | 3 | private function getDispatchableTargetList( array $subjectIdList ) { |
|
150 | |||
151 | } |
||
152 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: