phpstan fixes

This commit is contained in:
Dennis Eichhorn 2020-11-27 22:56:16 +01:00
parent 0c0a0bbf15
commit ed713a27cf
3 changed files with 19 additions and 33 deletions

View File

@ -20,6 +20,7 @@ use Modules\HumanResourceManagement\Models\EmployeeHistory;
use Modules\HumanResourceManagement\Models\EmployeeHistoryMapper;
use Modules\HumanResourceManagement\Models\EmployeeMapper;
use Modules\Profile\Models\Profile;
use Modules\Profile\Models\ProfileMapper;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
@ -121,7 +122,9 @@ final class ApiController extends Controller
$employees = [];
foreach ($accounts as $account) {
$employees[] = new Employee((int) $account);
/** @var Profile $profile Profile */
$profile = ProfileMapper::getFor((int) $account, 'account');
$employees[] = new Employee($profile);
}
return $employees;

View File

@ -17,6 +17,7 @@ namespace Modules\HumanResourceManagement\Models;
use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia;
use Modules\Profile\Models\Profile;
use Modules\Profile\Models\NullProfile;
use phpOMS\Contract\ArrayableInterface;
/**
@ -40,10 +41,10 @@ class Employee implements \JsonSerializable, ArrayableInterface
/**
* Account profile.
*
* @var null|int|Profile
* @var Profile
* @since 1.0.0
*/
public $profile = null;
public Profile $profile;
/**
* Employee image.
@ -96,13 +97,13 @@ class Employee implements \JsonSerializable, ArrayableInterface
/**
* Constructor.
*
* @param null|int|Profile $profile Account profile to initialize this employee with
* @param Profile $profile Account profile to initialize this employee with
*
* @since 1.0.0
*/
public function __construct($profile = null)
public function __construct(Profile $profile = null)
{
$this->profile = $profile;
$this->profile = $profile ?? new NullProfile();
$this->semiPrivateHash = \random_bytes(self::SEMI_PRIVATE_HASH_LENGTH);
$this->image = new NullMedia();
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\HumanResourceManagement\Models;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\DatabasePool;
/**
* Staff list class.
@ -29,19 +30,19 @@ class StaffList
/**
* Database instance.
*
* @var \phpOMS\DataStorage\Database\Pool
* @var DatabasePool
* @since 1.0.0
*/
private $dbPool = null;
private DatabasePool $dbPool;
/**
* Constructor.
*
* @param \phpOMS\DataStorage\Database\DatabasePool $dbPool Database pool instance
* @param DatabasePool $dbPool Database pool instance
*
* @since 1.0.0
*/
public function __construct($dbPool)
public function __construct(DatabasePool $dbPool)
{
$this->dbPool = $dbPool;
}
@ -59,29 +60,9 @@ class StaffList
*
* @since 1.0.0
*/
public function getList($filter = null, $offset = 0, $limit = 100)
public function getList($filter = null, $offset = 0, $limit = 100) : array
{
$result = null;
switch ($this->dbPool->get()->getType()) {
case DatabaseType::MYSQL:
$search = $this->dbPool->get()->generate_sql_filter($filter, true);
$sth = $this->dbPool->get()->con->prepare('SELECT
`hr_staff`.*
FROM
`hr_staff` '
. $search . 'LIMIT ' . $offset . ',' . $limit);
$sth->execute();
$result['list'] = $sth->fetchAll();
$sth = $this->dbPool->get()->con->prepare('SELECT FOUND_ROWS();');
$sth->execute();
$result['count'] = $sth->fetchAll()[0][0];
break;
}
$result = [];
return $result;
}
@ -93,7 +74,8 @@ class StaffList
*
* @since 1.0.0
*/
public function getStats()
public function getStats() : array
{
return [];
}
}