1 | <?php |
||
37 | class CsvImportAdapter implements ImportAdapterInterface, SerializerAwareAdapterInterface |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The trait that provides serializer functionality. |
||
42 | * |
||
43 | * @var \TechDivision\Import\Adapter\SerializerTrait |
||
44 | */ |
||
45 | use SerializerTrait; |
||
46 | |||
47 | /** |
||
48 | * The lexer instance. |
||
49 | * |
||
50 | * @var \Goodby\CSV\Import\Protocol\LexerInterface |
||
51 | */ |
||
52 | protected $lexer; |
||
53 | |||
54 | /** |
||
55 | * The interpreter instance. |
||
56 | * |
||
57 | * @var \Goodby\CSV\Import\Protocol\InterpreterInterface |
||
58 | */ |
||
59 | protected $interpreter; |
||
60 | |||
61 | /** |
||
62 | * The adapter's serializer instance. |
||
63 | * |
||
64 | * @var \TechDivision\Import\Serializers\SerializerInterface |
||
65 | */ |
||
66 | protected $serializer; |
||
67 | |||
68 | /** |
||
69 | * Initialize the adapter with the configuration. |
||
70 | * |
||
71 | * @param \Goodby\CSV\Import\Protocol\LexerInterface $lexer The lexer instance |
||
72 | * @param \Goodby\CSV\Import\Protocol\InterpreterInterface $interpreter The interpreter instance |
||
73 | */ |
||
74 | public function __construct(LexerInterface $lexer, InterpreterInterface $interpreter) |
||
79 | |||
80 | /** |
||
81 | * Overwrites the default CSV configuration values with the one from the passed configuration. |
||
82 | * |
||
83 | * @param \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface $importAdapterConfiguration The configuration to use the values from |
||
84 | * @param \TechDivision\Import\Serializers\ConfigurationAwareSerializerFactoryInterface $serializerFactory The serializer factory instance |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | public function init( |
||
125 | |||
126 | /** |
||
127 | * Imports the content of the CSV file with the passed filename. |
||
128 | * |
||
129 | * @param callable $callback The callback that processes the row |
||
130 | * @param string $filename The filename to process |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | public function import(callable $callback, $filename) |
||
144 | } |
||
145 |
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 implementation 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 interface: