Code Duplication    Length = 28-32 lines in 2 locations

source/Spiral/Database/DatabaseManager.php 1 location

@@ 71-98 (lines=28) @@
68
     *
69
     * @return Database
70
     */
71
    public function database($database = null)
72
    {
73
        if (empty($database)) {
74
            $database = $this->config->defaultDatabase();
75
        }
76
77
        //Spiral support ability to link multiple virtual databases together using aliases
78
        $database = $this->config->resolveAlias($database);
79
80
        if (isset($this->databases[$database])) {
81
            return $this->databases[$database];
82
        }
83
84
        if (!$this->config->hasDatabase($database)) {
85
            throw new DatabaseException(
86
                "Unable to create database, no presets for '{$database}' found."
87
            );
88
        }
89
90
        //No need to benchmark here, due connection will happen later
91
        $this->databases[$database] = $this->factory->make(Database::class, [
92
            'name'   => $database,
93
            'driver' => $this->driver($this->config->databaseConnection($database)),
94
            'prefix' => $this->config->databasePrefix($database)
95
        ]);
96
97
        return $this->databases[$database];
98
    }
99
100
    /**
101
     * Get driver by it's name. Every driver associated with configured connection, there is minor

source/Spiral/ODM/ODM.php 1 location

@@ 142-173 (lines=32) @@
139
     * @return MongoDatabase
140
     * @throws ODMException
141
     */
142
    public function database($database = null)
143
    {
144
        if (empty($database)) {
145
            $database = $this->config->defaultDatabase();
146
        }
147
148
        //Spiral support ability to link multiple virtual databases together using aliases
149
        $database = $this->config->resolveAlias($database);
150
151
        if (isset($this->databases[$database])) {
152
            return $this->databases[$database];
153
        }
154
155
        if (!$this->config->hasDatabase($database)) {
156
            throw new ODMException(
157
                "Unable to initiate mongo database, no presets for '{$database}' found."
158
            );
159
        }
160
161
        $benchmark = $this->benchmark('database', $database);
162
        try {
163
            $this->databases[$database] = $this->factory->make(MongoDatabase::class, [
164
                'name'   => $database,
165
                'config' => $this->config->databaseConfig($database),
166
                'odm'    => $this
167
            ]);
168
        } finally {
169
            $this->benchmark($benchmark);
170
        }
171
172
        return $this->databases[$database];
173
    }
174
175
    /**
176
     * {@inheritdoc}