Skip to content

Commit d6d0769

Browse files
lucaswerkmeisterWMDE bot
authored andcommitted
Document pitfall about Term / TermFallback classes
Plenty of places in Wikibase have something like this: 'value' => $term->getText(), 'language' => $term instanceof TermFallback ? $term->getActualLanguageCode() : $term->getLanguageCode(), This is unfortunate, but it’s not entirely clear how we best want to resolve it (I think Term and TermFallback should be entirely separate classes – you don’t want a TermFallback in an Item’s TermList either, do you? – but not 100% sure), nor whether cleaning this up is even worth the risk of breaking working code. Let’s just document it a bit better for now. Change-Id: Ia866ba175c95f0088eae5093bdf684afab83582a
1 parent 15ababd commit d6d0769

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/Term/Term.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/**
88
* Immutable value object.
99
*
10+
* Beware that {@link TermFallback} extends this class in an unintuitive way
11+
* which arguably even violates the Liskov substitution principle.
12+
*
1013
* @since 0.7.3
1114
*
1215
* @license GPL-2.0-or-later
@@ -45,6 +48,11 @@ public function __construct( $languageCode, $text ) {
4548
}
4649

4750
/**
51+
* Language code.
52+
*
53+
* Note that in {@link TermFallback}, this is the *requested* language code,
54+
* and there is a separate {@link TermFallback::getActualLanguageCode()} method.
55+
*
4856
* @return string
4957
*/
5058
public function getLanguageCode() {

0 commit comments

Comments
 (0)