Skip to content

Commit

Permalink
Docs - Fix @SInCE tag
Browse files Browse the repository at this point in the history
Arch - Remove getDatabase() from interface (needs to be protected, but that's not allowed in an interface; hadn't thought of that. Sorry, Allon!)
  • Loading branch information
nibra committed Mar 2, 2022
1 parent bda9982 commit bf0c004
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
17 changes: 8 additions & 9 deletions Tests/DatabaseAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
/**
* @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @copyright Copyright (C) 2022 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Database\Tests;

use Joomla\Database\DatabaseInterface;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\Exception\DatabaseNotFoundException;
use Joomla\Test\TestHelper;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -25,10 +24,10 @@ class DatabaseAwareTraitTest extends TestCase
/**
* @testdox Database can be set with setDatabase()
*
* @covers Joomla\Database\DatabaseAwareTrait
* @uses Joomla\Database\Database
* @covers \Joomla\Database\DatabaseAwareTrait
* @uses \Joomla\Database\Database
*/
public function testGetSetDatabase()
public function testGetSetDatabase(): void
{
$db = $this->createMock(DatabaseInterface::class);

Expand All @@ -41,9 +40,9 @@ public function testGetSetDatabase()
/**
* @testdox getDatabase() throws an DatabaseNotFoundException, if no database is set
*
* @covers Joomla\Database\DatabaseAwareTrait
* @covers \Joomla\Database\DatabaseAwareTrait
*/
public function testGetDatabaseException()
public function testGetDatabaseException(): void
{
$this->expectException(DatabaseNotFoundException::class);

Expand Down
16 changes: 3 additions & 13 deletions src/DatabaseAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Part of the Joomla Framework Database Package
*
* @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2022 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

Expand All @@ -11,28 +11,18 @@
/**
* Defines the interface for a DatabaseInterface aware class.
*
* @since 2.0.3
* @since 2.1.0
*/
interface DatabaseAwareInterface
{
/**
* Get the database.
*
* @return DatabaseInterface
*
* @since 2.0.3
* @throws DatabaseNotFoundException May be thrown if the database has not been set.
*/
public function getDatabase(): DatabaseInterface;

/**
* Set the database.
*
* @param DatabaseInterface $db The database.
*
* @return void
*
* @since 2.0.3
* @since 2.1.0
*/
public function setDatabase(DatabaseInterface $db): void;
}
21 changes: 11 additions & 10 deletions src/DatabaseAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Part of the Joomla Framework Database Package
*
* @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2022 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

Expand All @@ -13,30 +13,31 @@
/**
* Defines the trait for a Database Aware Class.
*
* @since 2.0.3
* @since 2.1.0
*/
trait DatabaseAwareTrait
{
/**
* Database
*
* @var DatabaseInterface
* @since 2.0.3
* @since 2.1.0
*/
private $_db;
private $databaseAwareTraitDatabase;

/**
* Get the database.
*
* @return DatabaseInterface
*
* @since 2.0.3
* @since 2.1.0
* @throws DatabaseNotFoundException May be thrown if the database has not been set.
*/
public function getDatabase()
protected function getDatabase(): DatabaseInterface
{
if ($this->_db) {
return $this->_db;
if ($this->databaseAwareTraitDatabase)
{
return $this->databaseAwareTraitDatabase;
}

throw new DatabaseNotFoundException('Database not set in ' . \get_class($this));
Expand All @@ -49,10 +50,10 @@ public function getDatabase()
*
* @return void
*
* @since 2.0.3
* @since 2.1.0
*/
public function setDatabase(DatabaseInterface $db): void
{
$this->_db = $db;
$this->databaseAwareTraitDatabase = $db;
}
}
4 changes: 2 additions & 2 deletions src/Exception/DatabaseNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Part of the Joomla Framework Database Package
*
* @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2022 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

Expand All @@ -11,7 +11,7 @@
/**
* No database is available.
*
* @since 2.0.3
* @since 2.1.0
*/
class DatabaseNotFoundException extends \RuntimeException
{
Expand Down

0 comments on commit bf0c004

Please sign in to comment.