Code Duplication    Length = 28-32 lines in 2 locations

source/Spiral/Database/DatabaseManager.php 1 location

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