These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
14 | * |
||
15 | * This software consists of voluntary contributions made by many individuals |
||
16 | * and is licensed under the MIT license. For more information, see |
||
17 | * <http://www.doctrine-project.org>. |
||
18 | */ |
||
19 | |||
20 | namespace Doctrine\ODM\MongoDB\Tools\Console\Command\Schema; |
||
21 | |||
22 | use Doctrine\ODM\MongoDB\SchemaManager; |
||
23 | use Symfony\Component\Console\Command\Command; |
||
24 | |||
25 | abstract class AbstractCommand extends Command |
||
26 | { |
||
27 | const DB = 'db'; |
||
28 | const COLLECTION = 'collection'; |
||
29 | const INDEX = 'index'; |
||
30 | |||
31 | abstract protected function processDocumentCollection(SchemaManager $sm, $document); |
||
32 | |||
33 | abstract protected function processCollection(SchemaManager $sm); |
||
34 | |||
35 | abstract protected function processDocumentDb(SchemaManager $sm, $document); |
||
36 | |||
37 | abstract protected function processDb(SchemaManager $sm); |
||
38 | |||
39 | abstract protected function processDocumentIndex(SchemaManager $sm, $document); |
||
40 | |||
41 | abstract protected function processIndex(SchemaManager $sm); |
||
42 | |||
43 | /** |
||
44 | * @return SchemaManager |
||
45 | */ |
||
46 | protected function getSchemaManager() |
||
47 | { |
||
48 | return $this->getDocumentManager()->getSchemaManager(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return \Doctrine\ODM\MongoDB\DocumentManager |
||
53 | */ |
||
54 | protected function getDocumentManager() |
||
55 | { |
||
56 | return $this->getHelper('documentManager')->getDocumentManager(); |
||
0 ignored issues
–
show
|
|||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return \Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory |
||
61 | */ |
||
62 | protected function getMetadataFactory() |
||
63 | { |
||
64 | return $this->getDocumentManager()->getMetadataFactory(); |
||
65 | } |
||
66 | } |
||
67 |
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: