1 | <?php |
||
26 | class FileRepository implements WritableRepository |
||
27 | { |
||
28 | use Repository\Capability\Notify; |
||
29 | |||
30 | const DEFAULT_SLICE_SIZE = 1000; |
||
31 | |||
32 | /** |
||
33 | * @var RangeFileDirectory |
||
34 | */ |
||
35 | private $charactersDirectory; |
||
36 | |||
37 | /** |
||
38 | * @var PropertyFileDirectory |
||
39 | */ |
||
40 | private $propertiesDirectory; |
||
41 | |||
42 | /** |
||
43 | * @var PropertyAggregators|AggregatorRelay[] |
||
44 | */ |
||
45 | private $aggregators; |
||
46 | |||
47 | /** |
||
48 | * @var Serializer |
||
49 | */ |
||
50 | private $serializer; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | */ |
||
55 | private $sliceSize; |
||
56 | |||
57 | /** |
||
58 | * @param RangeFileDirectory $charactersDirectory |
||
59 | * @param PropertyFileDirectory $propertiesDirectory |
||
60 | * @param PropertyAggregators $aggregators |
||
61 | * @param Serializer $serializer |
||
62 | * @param int $sliceSize |
||
63 | */ |
||
64 | public function __construct( |
||
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | public function getByCodepoint(Codepoint $codepoint) |
||
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | */ |
||
97 | public function getByCodepoints(Codepoint\Collection $codepoints) |
||
103 | |||
104 | /** |
||
105 | * @param Codepoint\Collection $codepoints |
||
106 | * @return \Generator |
||
107 | */ |
||
108 | private function yieldByCodepoints(Codepoint\Collection $codepoints) |
||
116 | |||
117 | /** |
||
118 | * @param Codepoint $codepoint |
||
119 | * @return RangeFile |
||
120 | * @throws CharacterNotFoundException |
||
121 | */ |
||
122 | private function getFileByCodepoint(Codepoint $codepoint) |
||
132 | |||
133 | /** |
||
134 | * {@inheritDoc} |
||
135 | */ |
||
136 | public function addMany(Collection $characters) |
||
149 | |||
150 | /** |
||
151 | * @param Range $range |
||
152 | * @param CodepointAssigned[] $characters |
||
153 | * @return CodepointAssigned[] |
||
154 | */ |
||
155 | private function createFileWithCharacters(Range $range, array $characters) |
||
162 | |||
163 | /** |
||
164 | * @param CodepointAssigned[] $characters |
||
165 | * @return string[] |
||
166 | */ |
||
167 | private function flattenCharacters(array $characters) |
||
179 | |||
180 | /** |
||
181 | * @param Codepoint\Range\Collection[] $ranges |
||
182 | * @return string[] |
||
183 | */ |
||
184 | public function flattenRanges(array $ranges) |
||
195 | |||
196 | /** |
||
197 | * @param CodepointAssigned[] $characters |
||
198 | */ |
||
199 | private function addCharactersToAggregators(array $characters) |
||
203 | |||
204 | /** |
||
205 | * @return bool |
||
206 | */ |
||
207 | private function writeAggregations() |
||
215 | |||
216 | /** |
||
217 | * {@inheritDoc} |
||
218 | */ |
||
219 | public function getAll() |
||
225 | |||
226 | /** |
||
227 | * @return \Generator |
||
228 | */ |
||
229 | private function readAll() |
||
241 | |||
242 | /** |
||
243 | * {@inheritDoc} |
||
244 | */ |
||
245 | public function getCodepointsByBlock(Block $block) |
||
253 | |||
254 | /** |
||
255 | * {@inheritDoc} |
||
256 | */ |
||
257 | public function getCodepointsByCategory(GeneralCategory $category) |
||
265 | |||
266 | /** |
||
267 | * @param Property $property |
||
268 | * @param string $key |
||
269 | * @param Exception $notFoundException |
||
270 | * @return Codepoint\Range[] |
||
271 | * @throws Exception |
||
272 | */ |
||
273 | private function resolveCodepointsByProperty(Property $property, $key, Exception $notFoundException) |
||
288 | |||
289 | /** |
||
290 | * {@inheritDoc} |
||
291 | */ |
||
292 | public function count() |
||
303 | } |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.