diff --git a/src/classes/App/ExceptionHandler.php b/src/classes/App/ExceptionHandler.php index 048e90b1..a27d189d 100644 --- a/src/classes/App/ExceptionHandler.php +++ b/src/classes/App/ExceptionHandler.php @@ -7,26 +7,26 @@ class ExceptionHandler { - private $getDetails; - private $changeStatus; - private $stringTools; + private GetDetails $getDetails; + private ChangeStatus $changeStatus; + private StringTools $stringTools; /** * @Inject */ - public function inject(GetDetails $getDetails, ChangeStatus $changeStatus, StringTools $stringTools) + public function inject(GetDetails $getDetails, ChangeStatus $changeStatus, StringTools $stringTools) :void { $this->getDetails = $getDetails; $this->changeStatus = $changeStatus; $this->stringTools = $stringTools; } - public function register() + public function register() :void { set_exception_handler([$this, "handle"]); } - public function handle($exception) + public function handle($exception) :void { $message = $exception->getMessage(); @@ -39,7 +39,7 @@ public function handle($exception) $hostId = $this->getDetails->getIdByUrlMatch($url); if (is_numeric($hostId)) { http_response_code(205); - $this->changeStatus->setOffline($hostId); + $this->changeStatus->setOffline((int) $hostId); } } diff --git a/src/classes/App/RouteApi.php b/src/classes/App/RouteApi.php index d2e9a6f9..739933c9 100755 --- a/src/classes/App/RouteApi.php +++ b/src/classes/App/RouteApi.php @@ -12,17 +12,17 @@ class RouteApi { - private $container; - private $recordAction; - private $getDetails; - private $hostList; - private $fetchAllowedProjects; - private $fetchUserDetails; - private $fetchUserProject; - private $invalidateToken; + private Container $container; + private RecordAction $recordAction; + private GetDetails $getDetails; + private HostList $hostList; + private FetchAllowedProjects $fetchAllowedProjects; + private FetchUserDetails $fetchUserDetails; + private FetchUserProject $fetchUserProject; + private InvalidateToken $invalidateToken; - private $project; - private $userId; + private ?string $project; + private int $userId; public function __construct( @@ -50,12 +50,12 @@ public function getRequestedProject() return $this->project; } - public function getUserId() + public function getUserId() :int { return $this->userId; } - public function route($pathParts, $headers, $returnResult = false) + public function route(array $pathParts, array $headers, bool $returnResult = false) { $userId = $headers["userid"]; @@ -75,7 +75,7 @@ public function route($pathParts, $headers, $returnResult = false) unset($pathParts[$methodkey]); - $controllerStr = "dhope0000\\LXDClient\\Controllers\\" . implode($pathParts, "\\"); + $controllerStr = "dhope0000\\LXDClient\\Controllers\\" . implode("\\", $pathParts); if (!class_exists($controllerStr)) { throw new \Exception("End point not found", 1); } elseif (method_exists($controllerStr, $method) !== true) { @@ -90,8 +90,14 @@ public function route($pathParts, $headers, $returnResult = false) $this->recordAction->record($userId, $controllerStr . "\\" . $method, $params); } + $callback = array($controller, $method); + + if (!is_callable($callback)) { + throw new \Exception("Cant find route", 1); + } + // TODO Pass provided arguments to controller - $data = call_user_func_array(array($controller, $method), $params); + $data = call_user_func_array($callback, $params); if ($returnResult) { return $data; @@ -101,7 +107,7 @@ public function route($pathParts, $headers, $returnResult = false) echo json_encode($data); } - public function orderParams($passedArguments, $class, $method, int $userId, $headers) + public function orderParams(array $passedArguments, string $class, string $method, int $userId, array $headers) :array { $reflectedMethod = new \ReflectionMethod($class, $method); $paramaters = $reflectedMethod->getParameters(); @@ -124,7 +130,7 @@ public function orderParams($passedArguments, $class, $method, int $userId, $hea $hasDefault = $param->isDefaultValueAvailable(); $type = $param->getType(); - if (!empty($type)) { + if (!empty($type) && $type instanceof \ReflectionNamedType) { $type = $type->getName(); } @@ -186,7 +192,7 @@ public function orderParams($passedArguments, $class, $method, int $userId, $hea return $o; } - private function canAccessProject($allowedProjects, $hostId, $project) + private function canAccessProject(array $allowedProjects, int $hostId, string $project) :void { if (!is_string($project) || strlen($project) == 0) { throw new \Exception("Cant work out which project to use", 1); diff --git a/src/classes/App/RouteAssets.php b/src/classes/App/RouteAssets.php index c84e4d37..59a9ce3b 100755 --- a/src/classes/App/RouteAssets.php +++ b/src/classes/App/RouteAssets.php @@ -3,7 +3,7 @@ class RouteAssets { - private $extensionMapping = [ + private array $extensionMapping = [ "css"=>"text/css", "js"=>"text/javascript", "png"=>"image/png", @@ -12,20 +12,29 @@ class RouteAssets "woff2"=>"font/woff2" ]; - public function route($path) + public function route(array $path) :void { $this->outputFile($path); } - public function outputFile($path) + public function outputFile(array $path) :void { - $path = __DIR__ . "/../../" . implode($path, "/"); + $path = __DIR__ . "/../../" . implode("/", $path); if (strpos($path, "?") !== false) { $path = substr($path, 0, strpos($path, "?")); } + if (!is_file($path)) { + throw new \Exception("Cant find asset", 1); + } + //get the last-modified-date of this very file $lastModified=filemtime($path); + + if (!$lastModified) { + throw new \Exception("Cant find asset", 1); + } + //get a unique hash of this file (etag) $etagFile = md5_file($path); //get the HTTP_IF_MODIFIED_SINCE header if set diff --git a/src/classes/App/RouteController.php b/src/classes/App/RouteController.php index 7c446f37..c41b60be 100755 --- a/src/classes/App/RouteController.php +++ b/src/classes/App/RouteController.php @@ -14,16 +14,16 @@ class RouteController { - private $validateToken; - private $userSession; - private $logUserIn; - private $routeApi; - private $routeView; - private $routeAssets; - private $session; - private $fetchUserDetails; + private ValidateToken $validateToken; + private UserSession $userSession; + private LogUserIn $logUserIn; + private RouteApi $routeApi; + private RouteView $routeView; + private RouteAssets $routeAssets; + private Session $session; + private FetchUserDetails $fetchUserDetails; - public $loginError = null; + public ?string $loginError = null; public function __construct( UserSession $userSession, @@ -118,6 +118,11 @@ public function routeRequest($explodedPath) $path = ""; if (isset($explodedPath[0])) { $parts = parse_url($explodedPath[0]); + + if ($parts == false) { + throw new \Exception("Couldn't parse '{$explodedPath[0]}'", 1); + } + $path = $parts["path"]; } diff --git a/src/classes/App/RouteView.php b/src/classes/App/RouteView.php index 76355e02..5dc9eb12 100755 --- a/src/classes/App/RouteView.php +++ b/src/classes/App/RouteView.php @@ -5,14 +5,15 @@ class RouteView { - private $container; - + /** @phpstan-ignore-next-line */ + private Container $container; + public function __construct(Container $container) { $this->container = $container; } - public function route($pathParts) + public function route(array $pathParts) { if (empty($pathParts)) { require __DIR__ . "/../../views/index.php"; diff --git a/src/classes/Controllers/AnalyticData/DownloadHistoryController.php b/src/classes/Controllers/AnalyticData/DownloadHistoryController.php index 17f37381..2b701837 100644 --- a/src/classes/Controllers/AnalyticData/DownloadHistoryController.php +++ b/src/classes/Controllers/AnalyticData/DownloadHistoryController.php @@ -6,14 +6,14 @@ class DownloadHistoryController { - private $downloadHistory; - + private DownloadHistory $downloadHistory; + public function __construct(DownloadHistory $downloadHistory) { $this->downloadHistory = $downloadHistory; } - public function download(int $userId) + public function download(int $userId) :array { return $this->downloadHistory->download($userId); } diff --git a/src/classes/Controllers/Backups/GetBackupsOverviewController.php b/src/classes/Controllers/Backups/GetBackupsOverviewController.php index 2b746da9..af838ad2 100644 --- a/src/classes/Controllers/Backups/GetBackupsOverviewController.php +++ b/src/classes/Controllers/Backups/GetBackupsOverviewController.php @@ -6,14 +6,14 @@ class GetBackupsOverviewController { - private $getBackupsOverview; + private GetBackupsOverview $getBackupsOverview; public function __construct(GetBackupsOverview $getBackupsOverview) { $this->getBackupsOverview = $getBackupsOverview; } - public function get($userId) + public function get(int $userId) :array { return $this->getBackupsOverview->get($userId); } diff --git a/src/classes/Controllers/Backups/RestoreBackupController.php b/src/classes/Controllers/Backups/RestoreBackupController.php index 89fdb750..6da2f507 100644 --- a/src/classes/Controllers/Backups/RestoreBackupController.php +++ b/src/classes/Controllers/Backups/RestoreBackupController.php @@ -8,7 +8,7 @@ class RestoreBackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $restoreBackup; + private RestoreBackup $restoreBackup; public function __construct(RestoreBackup $restoreBackup) { @@ -17,7 +17,7 @@ public function __construct(RestoreBackup $restoreBackup) /** * @Route("", name="Restore Local Backup To Host") */ - public function restore(int $userId, int $backupId, Host $targetHost) + public function restore(int $userId, int $backupId, Host $targetHost) :array { $response = $this->restoreBackup->restore($userId, $backupId, $targetHost); return ["state"=>"success", "message"=>"Restored Backup", "lxdResponse"=>$response]; diff --git a/src/classes/Controllers/Backups/Strategies/GetStrategiesController.php b/src/classes/Controllers/Backups/Strategies/GetStrategiesController.php index 11630351..573e8f4c 100644 --- a/src/classes/Controllers/Backups/Strategies/GetStrategiesController.php +++ b/src/classes/Controllers/Backups/Strategies/GetStrategiesController.php @@ -6,14 +6,14 @@ class GetStrategiesController { - private $fetchStrategies; + private FetchStrategies $fetchStrategies; public function __construct(FetchStrategies $fetchStrategies) { $this->fetchStrategies = $fetchStrategies; } - public function get() + public function get() :array { return $this->fetchStrategies->fetchAll(); } diff --git a/src/classes/Controllers/CloudConfig/CreateController.php b/src/classes/Controllers/CloudConfig/CreateController.php index 3b76bac9..4e3a02c1 100644 --- a/src/classes/Controllers/CloudConfig/CreateController.php +++ b/src/classes/Controllers/CloudConfig/CreateController.php @@ -6,7 +6,7 @@ class CreateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $create; + private Create $create; public function __construct(Create $create) { @@ -15,7 +15,7 @@ public function __construct(Create $create) /** * @Route("", name="Create Cloud Config") */ - public function create(string $name, string $namespace, $description = "") + public function create(string $name, string $namespace, string $description = "") { $this->create->create($name, $namespace, $description); return ["state"=>"success", "message"=>"Created cloud config"]; diff --git a/src/classes/Controllers/CloudConfig/DeleteController.php b/src/classes/Controllers/CloudConfig/DeleteController.php index e91f391c..efcdba22 100644 --- a/src/classes/Controllers/CloudConfig/DeleteController.php +++ b/src/classes/Controllers/CloudConfig/DeleteController.php @@ -6,8 +6,8 @@ class DeleteController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteCloudConfig; - + private DeleteCloudConfig $deleteCloudConfig; + public function __construct(DeleteCloudConfig $deleteCloudConfig) { $this->deleteCloudConfig = $deleteCloudConfig; @@ -15,7 +15,7 @@ public function __construct(DeleteCloudConfig $deleteCloudConfig) /** * @Route("", name="Delete Cloud Config") */ - public function delete(int $cloudConfigId) + public function delete(int $cloudConfigId) :array { $this->deleteCloudConfig->delete($cloudConfigId); return ["state"=>"success", "message"=>"Deleted Cloud Config"]; diff --git a/src/classes/Controllers/CloudConfig/DeployController.php b/src/classes/Controllers/CloudConfig/DeployController.php index ce327547..749c136e 100644 --- a/src/classes/Controllers/CloudConfig/DeployController.php +++ b/src/classes/Controllers/CloudConfig/DeployController.php @@ -7,8 +7,8 @@ class DeployController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deployConfigToContainer; - + private DeployConfigToContainer $deployConfigToContainer; + public function __construct(DeployConfigToContainer $deploy) { $this->deployConfigToContainer = $deploy; @@ -20,10 +20,10 @@ public function deploy( HostsCollection $hosts, string $containerName, int $cloudConfigId, - $additionalProfiles = [], - $gpus = [], + array $additionalProfiles = [], + array $gpus = [], string $project = "" - ) { + ) :array { $response = $this->deployConfigToContainer->deploy( $hosts, $containerName, diff --git a/src/classes/Controllers/CloudConfig/GetAllController.php b/src/classes/Controllers/CloudConfig/GetAllController.php index 9f02bb55..6a80ba62 100644 --- a/src/classes/Controllers/CloudConfig/GetAllController.php +++ b/src/classes/Controllers/CloudConfig/GetAllController.php @@ -5,14 +5,14 @@ class GetAllController { - private $getConfigs; - + private GetConfigs $getConfigs; + public function __construct(GetConfigs $getConfigs) { $this->getConfigs = $getConfigs; } - public function getAll() + public function getAll() :array { return $this->getConfigs->getAll(); } diff --git a/src/classes/Controllers/CloudConfig/GetDetailsController.php b/src/classes/Controllers/CloudConfig/GetDetailsController.php index 1d134b24..9a75f0f1 100644 --- a/src/classes/Controllers/CloudConfig/GetDetailsController.php +++ b/src/classes/Controllers/CloudConfig/GetDetailsController.php @@ -5,14 +5,14 @@ class GetDetailsController { - private $getDetails; + private GetDetails $getDetails; public function __construct(GetDetails $getDetails) { $this->getDetails = $getDetails; } - public function get(int $id) + public function get(int $id) :array { return $this->getDetails->get($id); } diff --git a/src/classes/Controllers/CloudConfig/Search/SearchController.php b/src/classes/Controllers/CloudConfig/Search/SearchController.php index 85391633..d3ff0e74 100644 --- a/src/classes/Controllers/CloudConfig/Search/SearchController.php +++ b/src/classes/Controllers/CloudConfig/Search/SearchController.php @@ -6,14 +6,14 @@ class SearchController { - private $searchCloudConfig; - + private SearchCloudConfig $searchCloudConfig; + public function __construct(SearchCloudConfig $searchCloudConfig) { $this->searchCloudConfig = $searchCloudConfig; } - public function searchAll(string $criteria) + public function searchAll(string $criteria) :array { return $this->searchCloudConfig->searchAll($criteria); } diff --git a/src/classes/Controllers/CloudConfig/UpdateController.php b/src/classes/Controllers/CloudConfig/UpdateController.php index 23545cc6..305067b0 100644 --- a/src/classes/Controllers/CloudConfig/UpdateController.php +++ b/src/classes/Controllers/CloudConfig/UpdateController.php @@ -6,8 +6,8 @@ class UpdateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $update; - + private Update $update; + public function __construct(Update $update) { $this->update = $update; @@ -15,7 +15,7 @@ public function __construct(Update $update) /** * @Route("", name="Update Cloud Config") */ - public function update(int $cloudConfigId, string $code, array $imageDetails, array $envVariables = []) + public function update(int $cloudConfigId, string $code, array $imageDetails, array $envVariables = []) :array { $this->update->update($cloudConfigId, $code, $imageDetails, $envVariables); return ["state"=>"success", "message"=>"Save cloud config"]; diff --git a/src/classes/Controllers/Clusters/GetClusterController.php b/src/classes/Controllers/Clusters/GetClusterController.php index 56993630..d0971d59 100644 --- a/src/classes/Controllers/Clusters/GetClusterController.php +++ b/src/classes/Controllers/Clusters/GetClusterController.php @@ -7,16 +7,16 @@ class GetClusterController { - private $getCluster; - private $validatePermissions; - + private GetCluster $getCluster; + private ValidatePermissions $validatePermissions; + public function __construct(GetCluster $getCluster, ValidatePermissions $validatePermissions) { $this->getCluster = $getCluster; $this->validatePermissions = $validatePermissions; } - public function get(int $userId, $cluster) + public function get(int $userId, int $cluster) { $this->validatePermissions->isAdminOrThrow($userId); return $this->getCluster->get($cluster); diff --git a/src/classes/Controllers/Dashboard/GetController.php b/src/classes/Controllers/Dashboard/GetController.php index bcd9f408..a5d34595 100644 --- a/src/classes/Controllers/Dashboard/GetController.php +++ b/src/classes/Controllers/Dashboard/GetController.php @@ -6,14 +6,14 @@ class GetController { - private $getDashboard; - + private GetDashboard $getDashboard; + public function __construct(GetDashboard $getDashboard) { $this->getDashboard = $getDashboard; } - public function get($userId, string $history = "-30 minutes") + public function get(int $userId, string $history = "-30 minutes") :array { return $this->getDashboard->get($userId); } diff --git a/src/classes/Controllers/Deployments/CreateController.php b/src/classes/Controllers/Deployments/CreateController.php index aff643b4..794560f3 100644 --- a/src/classes/Controllers/Deployments/CreateController.php +++ b/src/classes/Controllers/Deployments/CreateController.php @@ -7,8 +7,8 @@ class CreateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createDeployment; - + private CreateDeployment $createDeployment; + public function __construct(CreateDeployment $createDeployment) { $this->createDeployment = $createDeployment; @@ -16,7 +16,7 @@ public function __construct(CreateDeployment $createDeployment) /** * @Route("", name="Create Deployment") */ - public function create(string $name, array $cloudConfigs) + public function create(string $name, array $cloudConfigs) :array { $deploymentId = $this->createDeployment->create($name, $cloudConfigs); return [ diff --git a/src/classes/Controllers/Deployments/DeleteDeploymentController.php b/src/classes/Controllers/Deployments/DeleteDeploymentController.php index 67af76ec..64877b6a 100644 --- a/src/classes/Controllers/Deployments/DeleteDeploymentController.php +++ b/src/classes/Controllers/Deployments/DeleteDeploymentController.php @@ -7,8 +7,8 @@ class DeleteDeploymentController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteDeployment; - + private DeleteDeployment $deleteDeployment; + public function __construct(DeleteDeployment $deleteDeployment) { $this->deleteDeployment = $deleteDeployment; @@ -16,7 +16,7 @@ public function __construct(DeleteDeployment $deleteDeployment) /** * @Route("", name="Delete Deployment") */ - public function delete(int $userId, int $deploymentId) + public function delete(int $userId, int $deploymentId) :array { $this->deleteDeployment->delete($userId, $deploymentId); return ["state"=>"success", "message"=>"Deleted deployment"]; diff --git a/src/classes/Controllers/Deployments/DeployController.php b/src/classes/Controllers/Deployments/DeployController.php index 1d32e295..e7cec68f 100644 --- a/src/classes/Controllers/Deployments/DeployController.php +++ b/src/classes/Controllers/Deployments/DeployController.php @@ -7,8 +7,8 @@ class DeployController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deploy; - + private Deploy $deploy; + public function __construct(Deploy $deploy) { $this->deploy = $deploy; @@ -16,7 +16,7 @@ public function __construct(Deploy $deploy) /** * @Route("", name="Deploy Deployment") */ - public function deploy(int $userId, int $deploymentId, array $instances) + public function deploy(int $userId, int $deploymentId, array $instances) :array { $data = $this->deploy->deploy($userId, $deploymentId, $instances); return ["state"=>"success", "message"=>"Deployment complete", "data"=>$data]; diff --git a/src/classes/Controllers/Deployments/GetCloudsConfigController.php b/src/classes/Controllers/Deployments/GetCloudsConfigController.php index 2900c8e5..085042df 100644 --- a/src/classes/Controllers/Deployments/GetCloudsConfigController.php +++ b/src/classes/Controllers/Deployments/GetCloudsConfigController.php @@ -6,14 +6,14 @@ class GetCloudsConfigController { - private $getCloudConfigs; - + private GetCloudConfigs $getCloudConfigs; + public function __construct(GetCloudConfigs $getCloudConfigs) { $this->getCloudConfigs = $getCloudConfigs; } - public function get(int $userId, int $deploymentId) + public function get(int $userId, int $deploymentId) :array { return $this->getCloudConfigs->getAll($userId, $deploymentId); } diff --git a/src/classes/Controllers/Deployments/GetController.php b/src/classes/Controllers/Deployments/GetController.php index fd34238d..6fec75a4 100644 --- a/src/classes/Controllers/Deployments/GetController.php +++ b/src/classes/Controllers/Deployments/GetController.php @@ -6,14 +6,14 @@ class GetController { - private $getDeployments; + private GetDeployments $getDeployments; public function __construct(GetDeployments $getDeployments) { $this->getDeployments = $getDeployments; } - public function getAll(int $userId) + public function getAll(int $userId) :array { return $this->getDeployments->getAll($userId); } diff --git a/src/classes/Controllers/Deployments/GetDeploymentController.php b/src/classes/Controllers/Deployments/GetDeploymentController.php index e11c3e22..64a98556 100644 --- a/src/classes/Controllers/Deployments/GetDeploymentController.php +++ b/src/classes/Controllers/Deployments/GetDeploymentController.php @@ -6,7 +6,7 @@ class GetDeploymentController { - private $getDeployment; + private GetDeployment $getDeployment; public function __construct(GetDeployment $getDeployment) { diff --git a/src/classes/Controllers/Deployments/Projects/GetDeploymentProjectsController.php b/src/classes/Controllers/Deployments/Projects/GetDeploymentProjectsController.php index 1785c159..d2d5987e 100644 --- a/src/classes/Controllers/Deployments/Projects/GetDeploymentProjectsController.php +++ b/src/classes/Controllers/Deployments/Projects/GetDeploymentProjectsController.php @@ -8,8 +8,8 @@ class GetDeploymentProjectsController { - private $authoriseDeploymentAccess; - private $fetchDeploymentProjects; + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private FetchDeploymentProjects $fetchDeploymentProjects; public function __construct(AuthoriseDeploymentAccess $authoriseDeploymentAccess, FetchDeploymentProjects $fetchDeploymentProjects) { @@ -19,7 +19,7 @@ public function __construct(AuthoriseDeploymentAccess $authoriseDeploymentAccess /** * @Route("", name="Get Deployment Projects") */ - public function get(int $userId, int $deploymentId) + public function get(int $userId, int $deploymentId) :array { $this->authoriseDeploymentAccess->authorise($userId, $deploymentId); return $this->fetchDeploymentProjects->fetchAll($deploymentId); diff --git a/src/classes/Controllers/Deployments/Projects/SetDeploymentProjectsController.php b/src/classes/Controllers/Deployments/Projects/SetDeploymentProjectsController.php index 9044f71a..d1fcafa1 100644 --- a/src/classes/Controllers/Deployments/Projects/SetDeploymentProjectsController.php +++ b/src/classes/Controllers/Deployments/Projects/SetDeploymentProjectsController.php @@ -8,8 +8,8 @@ class SetDeploymentProjectsController { - private $setDeploymentProjects; - private $container; + private SetDeploymentProjects $setDeploymentProjects; + private Container $container; public function __construct(SetDeploymentProjects $setDeploymentProjects, Container $container) { @@ -19,7 +19,7 @@ public function __construct(SetDeploymentProjects $setDeploymentProjects, Contai /** * @Route("", name="Set Deployment Projects") */ - public function set(int $userId, int $deploymentId, array $newProjectsLayout) + public function set(int $userId, int $deploymentId, array $newProjectsLayout) :array { $this->container->call(["dhope0000\LXDClient\Model\Database\Database", "beginTransaction"]); $this->setDeploymentProjects->set($userId, $deploymentId, $newProjectsLayout); diff --git a/src/classes/Controllers/Deployments/StartDeploymentController.php b/src/classes/Controllers/Deployments/StartDeploymentController.php index 498bb1ee..4f496c10 100644 --- a/src/classes/Controllers/Deployments/StartDeploymentController.php +++ b/src/classes/Controllers/Deployments/StartDeploymentController.php @@ -8,8 +8,8 @@ class StartDeploymentController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $changeDeploymentState; - + private ChangeDeploymentState $changeDeploymentState; + public function __construct(ChangeDeploymentState $changeDeploymentState) { $this->changeDeploymentState = $changeDeploymentState; diff --git a/src/classes/Controllers/Deployments/StopDeploymentController.php b/src/classes/Controllers/Deployments/StopDeploymentController.php index 348ca904..4822c92e 100644 --- a/src/classes/Controllers/Deployments/StopDeploymentController.php +++ b/src/classes/Controllers/Deployments/StopDeploymentController.php @@ -8,8 +8,8 @@ class StopDeploymentController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $changeDeploymentState; - + private ChangeDeploymentState $changeDeploymentState; + public function __construct(ChangeDeploymentState $changeDeploymentState) { $this->changeDeploymentState = $changeDeploymentState; diff --git a/src/classes/Controllers/Deployments/UpdatePhoneHomeController.php b/src/classes/Controllers/Deployments/UpdatePhoneHomeController.php index 13c52738..06b673fc 100644 --- a/src/classes/Controllers/Deployments/UpdatePhoneHomeController.php +++ b/src/classes/Controllers/Deployments/UpdatePhoneHomeController.php @@ -6,8 +6,8 @@ class UpdatePhoneHomeController { - private $updatePhoneHomeTime; - + private UpdatePhoneHomeTime $updatePhoneHomeTime; + public function __construct(UpdatePhoneHomeTime $updatePhoneHomeTime) { $this->updatePhoneHomeTime = $updatePhoneHomeTime; diff --git a/src/classes/Controllers/Hosts/AddHostsController.php b/src/classes/Controllers/Hosts/AddHostsController.php index 905c5c17..cd5dc4a8 100644 --- a/src/classes/Controllers/Hosts/AddHostsController.php +++ b/src/classes/Controllers/Hosts/AddHostsController.php @@ -6,8 +6,8 @@ class AddHostsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $addHosts; - + private AddHosts $addHosts; + public function __construct(AddHosts $addHosts) { $this->addHosts = $addHosts; @@ -15,7 +15,7 @@ public function __construct(AddHosts $addHosts) /** * @Route("", name="Add Hosts") */ - public function add($userId, array $hostsDetails) + public function add(int $userId, array $hostsDetails) { $this->addHosts->add($userId, $hostsDetails); return ["state"=>"success", "messages"=>"Added Hosts"]; diff --git a/src/classes/Controllers/Hosts/Certificates/RenewHostCertificateController.php b/src/classes/Controllers/Hosts/Certificates/RenewHostCertificateController.php index 89cad07f..dff7eded 100644 --- a/src/classes/Controllers/Hosts/Certificates/RenewHostCertificateController.php +++ b/src/classes/Controllers/Hosts/Certificates/RenewHostCertificateController.php @@ -3,27 +3,24 @@ use dhope0000\LXDClient\Objects\Host; use dhope0000\LXDClient\Tools\Hosts\Certificates\RenewCert; -use dhope0000\LXDClient\Model\Users\FetchUserDetails; +use dhope0000\LXDClient\Tools\User\ValidatePermissions; class RenewHostCertificateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $renewCert; - private $fetchUserDetails; + private RenewCert $renewCert; + private ValidatePermissions $validatePermissions; - public function __construct(RenewCert $renewCert, FetchUserDetails $fetchUserDetails) + public function __construct(RenewCert $renewCert, ValidatePermissions $validatePermissions) { $this->renewCert = $renewCert; - $this->fetchUserDetails = $fetchUserDetails; + $this->validatePermissions = $validatePermissions; } /** * @Route("", name="Renew LXDMosaic certificate with LXD") */ public function renew(int $userId, Host $host) { - $isAdmin = $this->fetchUserDetails->isAdmin($userId) === '1'; - if (!$isAdmin) { - throw new \Exception("No access", 1); - } + $this->validatePermissions->isAdminOrThrow($userId); $this->renewCert->renew($host); return ["state"=>"success", "messages"=>"Renewed Certificate"]; } diff --git a/src/classes/Controllers/Hosts/DeleteHostController.php b/src/classes/Controllers/Hosts/DeleteHostController.php index a99688c7..84b8b50e 100644 --- a/src/classes/Controllers/Hosts/DeleteHostController.php +++ b/src/classes/Controllers/Hosts/DeleteHostController.php @@ -7,8 +7,8 @@ class DeleteHostController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $removeHost; - private $container; + private RemoveHost $removeHost; + private Container $container; public function __construct(RemoveHost $removeHost, Container $container) { diff --git a/src/classes/Controllers/Hosts/GPU/GetAllController.php b/src/classes/Controllers/Hosts/GPU/GetAllController.php index 0c49fbd8..b8d21501 100644 --- a/src/classes/Controllers/Hosts/GPU/GetAllController.php +++ b/src/classes/Controllers/Hosts/GPU/GetAllController.php @@ -7,8 +7,8 @@ class GetAllController { - private $getAll; - + private GetAll $getAll; + public function __construct(GetAll $getAll) { $this->getAll = $getAll; diff --git a/src/classes/Controllers/Hosts/GetHostOverviewController.php b/src/classes/Controllers/Hosts/GetHostOverviewController.php index 832082b9..32344a4c 100644 --- a/src/classes/Controllers/Hosts/GetHostOverviewController.php +++ b/src/classes/Controllers/Hosts/GetHostOverviewController.php @@ -6,8 +6,8 @@ class GetHostOverviewController { - private $getHostOverview; - + private GetHostOverview $getHostOverview; + public function __construct(GetHostOverview $getHostOverview) { $this->getHostOverview = $getHostOverview; diff --git a/src/classes/Controllers/Hosts/GetHostsController.php b/src/classes/Controllers/Hosts/GetHostsController.php index 5322e3c3..86c7954f 100755 --- a/src/classes/Controllers/Hosts/GetHostsController.php +++ b/src/classes/Controllers/Hosts/GetHostsController.php @@ -2,25 +2,22 @@ namespace dhope0000\LXDClient\Controllers\Hosts; use dhope0000\LXDClient\Tools\Hosts\GetHostsOverview; -use dhope0000\LXDClient\Model\Users\FetchUserDetails; +use dhope0000\LXDClient\Tools\User\ValidatePermissions; class GetHostsController { - private $getHostsOverview; - private $fetchUserDetails; - - public function __construct(GetHostsOverview $getHostsOverview, FetchUserDetails $fetchUserDetails) + private GetHostsOverview $getHostsOverview; + private ValidatePermissions $validatePermissions; + + public function __construct(GetHostsOverview $getHostsOverview, ValidatePermissions $validatePermissions) { $this->getHostsOverview = $getHostsOverview; - $this->fetchUserDetails = $fetchUserDetails; + $this->validatePermissions = $validatePermissions; } public function getAllHosts(int $userId) { - $isAdmin = $this->fetchUserDetails->isAdmin($userId) === '1'; - if (!$isAdmin) { - throw new \Exception("No access", 1); - } + $this->validatePermissions->isAdminOrThrow($userId); return $this->getHostsOverview->get(); } } diff --git a/src/classes/Controllers/Hosts/Instances/AddProxyDeviceController.php b/src/classes/Controllers/Hosts/Instances/AddProxyDeviceController.php index 3c7c6b95..7adf6125 100644 --- a/src/classes/Controllers/Hosts/Instances/AddProxyDeviceController.php +++ b/src/classes/Controllers/Hosts/Instances/AddProxyDeviceController.php @@ -7,8 +7,8 @@ class AddProxyDeviceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $addProxyDevice; - + private AddProxyDevice $addProxyDevice; + public function __construct(AddProxyDevice $addProxyDevice) { $this->addProxyDevice = $addProxyDevice; diff --git a/src/classes/Controllers/Hosts/Instances/DeleteInstancesController.php b/src/classes/Controllers/Hosts/Instances/DeleteInstancesController.php index a97d3175..541d488e 100644 --- a/src/classes/Controllers/Hosts/Instances/DeleteInstancesController.php +++ b/src/classes/Controllers/Hosts/Instances/DeleteInstancesController.php @@ -7,8 +7,8 @@ class DeleteInstancesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteInstances; - + private DeleteInstances $deleteInstances; + public function __construct(DeleteInstances $deleteInstances) { $this->deleteInstances = $deleteInstances; diff --git a/src/classes/Controllers/Hosts/Instances/DeleteProxyDeviceController.php b/src/classes/Controllers/Hosts/Instances/DeleteProxyDeviceController.php index 4af74d51..98ad668c 100644 --- a/src/classes/Controllers/Hosts/Instances/DeleteProxyDeviceController.php +++ b/src/classes/Controllers/Hosts/Instances/DeleteProxyDeviceController.php @@ -7,8 +7,8 @@ class DeleteProxyDeviceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteProxyDevice; - + private DeleteProxyDevice $deleteProxyDevice; + public function __construct(DeleteProxyDevice $deleteProxyDevice) { $this->deleteProxyDevice = $deleteProxyDevice; diff --git a/src/classes/Controllers/Hosts/Instances/GetAllProxyDevicesController.php b/src/classes/Controllers/Hosts/Instances/GetAllProxyDevicesController.php index 950f7d37..8da6c089 100644 --- a/src/classes/Controllers/Hosts/Instances/GetAllProxyDevicesController.php +++ b/src/classes/Controllers/Hosts/Instances/GetAllProxyDevicesController.php @@ -7,8 +7,8 @@ class GetAllProxyDevicesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getAllProxyDevices; - + private GetAllProxyDevices $getAllProxyDevices; + public function __construct(GetAllProxyDevices $getAllProxyDevices) { $this->getAllProxyDevices = $getAllProxyDevices; diff --git a/src/classes/Controllers/Hosts/Instances/GetHostsInstancesController.php b/src/classes/Controllers/Hosts/Instances/GetHostsInstancesController.php index 05f46fc3..7aec5bee 100644 --- a/src/classes/Controllers/Hosts/Instances/GetHostsInstancesController.php +++ b/src/classes/Controllers/Hosts/Instances/GetHostsInstancesController.php @@ -6,8 +6,8 @@ class GetHostsInstancesController { - private $getHostsInstances; - + private GetHostsInstances $getHostsInstances; + public function __construct(GetHostsInstances $getHostsInstances) { $this->getHostsInstances = $getHostsInstances; diff --git a/src/classes/Controllers/Hosts/Instances/StartInstancesController.php b/src/classes/Controllers/Hosts/Instances/StartInstancesController.php index 762bece5..7ded8a3d 100644 --- a/src/classes/Controllers/Hosts/Instances/StartInstancesController.php +++ b/src/classes/Controllers/Hosts/Instances/StartInstancesController.php @@ -7,8 +7,8 @@ class StartInstancesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $startInstances; - + private StartInstances $startInstances; + public function __construct(StartInstances $startInstances) { $this->startInstances = $startInstances; diff --git a/src/classes/Controllers/Hosts/Instances/StopInstancesController.php b/src/classes/Controllers/Hosts/Instances/StopInstancesController.php index 4ef55b84..7887544c 100644 --- a/src/classes/Controllers/Hosts/Instances/StopInstancesController.php +++ b/src/classes/Controllers/Hosts/Instances/StopInstancesController.php @@ -7,8 +7,8 @@ class StopInstancesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $stopInstances; - + private StopInstances $stopInstances; + public function __construct(StopInstances $stopInstances) { $this->stopInstances = $stopInstances; diff --git a/src/classes/Controllers/Hosts/SearchHosts.php b/src/classes/Controllers/Hosts/SearchHosts.php index 9783677f..37bd9a63 100755 --- a/src/classes/Controllers/Hosts/SearchHosts.php +++ b/src/classes/Controllers/Hosts/SearchHosts.php @@ -8,11 +8,11 @@ class SearchHosts { - private $hostList; - private $hasExtension; - private $fetchUserDetails; - private $fetchAllowedProjects; - + private HostList $hostList; + private HasExtension $hasExtension; + private FetchUserDetails $fetchUserDetails; + private FetchAllowedProjects $fetchAllowedProjects; + public function __construct( HostList $hostList, HasExtension $hasExtension, diff --git a/src/classes/Controllers/Hosts/Settings/GetHostSettingsController.php b/src/classes/Controllers/Hosts/Settings/GetHostSettingsController.php index 4eed04d3..f36feca6 100644 --- a/src/classes/Controllers/Hosts/Settings/GetHostSettingsController.php +++ b/src/classes/Controllers/Hosts/Settings/GetHostSettingsController.php @@ -7,7 +7,7 @@ class GetHostSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $validatePermissions; + private ValidatePermissions $validatePermissions; public function __construct(ValidatePermissions $validatePermissions) { @@ -16,7 +16,7 @@ public function __construct(ValidatePermissions $validatePermissions) /** * @Route("", name="Get hosts settings") */ - public function get($userId, Host $host) + public function get(int $userId, Host $host) { $this->validatePermissions->isAdminOrThrow($userId); return $host->host->info()["config"]; diff --git a/src/classes/Controllers/Hosts/Settings/UpdateHostSettingsController.php b/src/classes/Controllers/Hosts/Settings/UpdateHostSettingsController.php index 14606629..6c6def62 100644 --- a/src/classes/Controllers/Hosts/Settings/UpdateHostSettingsController.php +++ b/src/classes/Controllers/Hosts/Settings/UpdateHostSettingsController.php @@ -7,7 +7,7 @@ class UpdateHostSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $validatePermissions; + private ValidatePermissions $validatePermissions; public function __construct(ValidatePermissions $validatePermissions) { @@ -16,7 +16,7 @@ public function __construct(ValidatePermissions $validatePermissions) /** * @Route("", name="Get hosts settings") */ - public function update($userId, Host $host, array $settings) + public function update(int $userId, Host $host, array $settings) { $this->validatePermissions->isAdminOrThrow($userId); $info = $host->host->info(); diff --git a/src/classes/Controllers/Hosts/Settings/UpdateSettingsController.php b/src/classes/Controllers/Hosts/Settings/UpdateSettingsController.php index be76f7e1..51e54118 100644 --- a/src/classes/Controllers/Hosts/Settings/UpdateSettingsController.php +++ b/src/classes/Controllers/Hosts/Settings/UpdateSettingsController.php @@ -6,8 +6,8 @@ class UpdateSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $updateHostSettings; - + private UpdateHostSettings $updateHostSettings; + public function __construct(UpdateHostSettings $updateHostSettings) { $this->updateHostSettings = $updateHostSettings; diff --git a/src/classes/Controllers/Hosts/Warnings/AckWarningController.php b/src/classes/Controllers/Hosts/Warnings/AckWarningController.php index abc6be80..942e5c1d 100644 --- a/src/classes/Controllers/Hosts/Warnings/AckWarningController.php +++ b/src/classes/Controllers/Hosts/Warnings/AckWarningController.php @@ -6,7 +6,7 @@ class AckWarningController { - private $ackWarning; + private AckWarning $ackWarning; public function __construct(AckWarning $ackWarning) { diff --git a/src/classes/Controllers/Hosts/Warnings/DeleteWarningController.php b/src/classes/Controllers/Hosts/Warnings/DeleteWarningController.php index 80fea0e4..962fdb68 100644 --- a/src/classes/Controllers/Hosts/Warnings/DeleteWarningController.php +++ b/src/classes/Controllers/Hosts/Warnings/DeleteWarningController.php @@ -6,7 +6,7 @@ class DeleteWarningController { - private $deleteWarning; + private DeleteWarning $deleteWarning; public function __construct(DeleteWarning $deleteWarning) { diff --git a/src/classes/Controllers/Images/Aliases/CreateController.php b/src/classes/Controllers/Images/Aliases/CreateController.php index ee48ebbd..af38c45e 100644 --- a/src/classes/Controllers/Images/Aliases/CreateController.php +++ b/src/classes/Controllers/Images/Aliases/CreateController.php @@ -8,8 +8,8 @@ class CreateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createAlias; - + private CreateAlias $createAlias; + public function __construct(CreateAlias $createAlias) { $this->createAlias = $createAlias; @@ -17,7 +17,7 @@ public function __construct(CreateAlias $createAlias) /** * @Route("", name="Create Image Alias") */ - public function create(Host $host, string $fingerprint, string $name, string $description = "") + public function create(Host $host, string $fingerprint, string $name, string $description = "") :array { $lxdResponse = $this->createAlias->create( $host, diff --git a/src/classes/Controllers/Images/Aliases/DeleteController.php b/src/classes/Controllers/Images/Aliases/DeleteController.php index 82898823..4c42762e 100644 --- a/src/classes/Controllers/Images/Aliases/DeleteController.php +++ b/src/classes/Controllers/Images/Aliases/DeleteController.php @@ -8,8 +8,8 @@ class DeleteController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteAlias; - + private DeleteAlias $deleteAlias; + public function __construct(DeleteAlias $deleteAlias) { $this->deleteAlias = $deleteAlias; @@ -17,7 +17,7 @@ public function __construct(DeleteAlias $deleteAlias) /** * @Route("", name="Delete Image Alias") */ - public function delete(Host $host, string $name) + public function delete(Host $host, string $name) :array { $lxdResponse = $this->deleteAlias->delete($host, $name); return ["state"=>"success", "message"=>"Deleted alias", "lxdResponse"=>$lxdResponse]; diff --git a/src/classes/Controllers/Images/Aliases/RenameController.php b/src/classes/Controllers/Images/Aliases/RenameController.php index 534838ae..57f7dbc7 100644 --- a/src/classes/Controllers/Images/Aliases/RenameController.php +++ b/src/classes/Controllers/Images/Aliases/RenameController.php @@ -8,8 +8,8 @@ class RenameController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $renameAlias; - + private RenameAlias $renameAlias; + public function __construct(RenameAlias $renameAlias) { $this->renameAlias = $renameAlias; @@ -17,7 +17,7 @@ public function __construct(RenameAlias $renameAlias) /** * @Route("", name="Rename Image Alias") */ - public function rename(Host $host, string $name, string $newName) + public function rename(Host $host, string $name, string $newName) :array { $lxdResponse = $this->renameAlias->rename($host, $name, $newName); return ["state"=>"success", "message"=>"Renamed alias", "lxdResponse"=>$lxdResponse]; diff --git a/src/classes/Controllers/Images/Aliases/UpdateDescriptionController.php b/src/classes/Controllers/Images/Aliases/UpdateDescriptionController.php index 4be3e409..a5d47edd 100644 --- a/src/classes/Controllers/Images/Aliases/UpdateDescriptionController.php +++ b/src/classes/Controllers/Images/Aliases/UpdateDescriptionController.php @@ -8,8 +8,8 @@ class UpdateDescriptionController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $updateDescription; - + private UpdateDescription $updateDescription; + public function __construct(UpdateDescription $updateDescription) { $this->updateDescription = $updateDescription; @@ -17,7 +17,7 @@ public function __construct(UpdateDescription $updateDescription) /** * @Route("", name="Update Image Alias Description") */ - public function update(Host $host, string $fingerprint, string $name, string $description = "") + public function update(Host $host, string $fingerprint, string $name, string $description = "") :array { $lxdResponse = $this->updateDescription->update($host, $fingerprint, $name, $description); return ["state"=>"success", "message"=>"Updated alias description", "lxdResponse"=>$lxdResponse]; diff --git a/src/classes/Controllers/Images/DeleteImagesController.php b/src/classes/Controllers/Images/DeleteImagesController.php index d5856266..3db2ce44 100755 --- a/src/classes/Controllers/Images/DeleteImagesController.php +++ b/src/classes/Controllers/Images/DeleteImagesController.php @@ -7,8 +7,8 @@ class DeleteImagesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteImages; - + private DeleteImages $deleteImages; + public function __construct(DeleteImages $deleteImages) { $this->deleteImages = $deleteImages; @@ -16,7 +16,7 @@ public function __construct(DeleteImages $deleteImages) /** * @Route("", name="Delete Images From Hosts") */ - public function delete(int $userId, $imageData) + public function delete(int $userId, array $imageData) :array { $lxdResponse = $this->deleteImages->delete($userId, $imageData); return ["state"=>"success", "message"=>"Deleting Image", "lxdResponse"=>$lxdResponse]; diff --git a/src/classes/Controllers/Images/GetImagePropertiesController.php b/src/classes/Controllers/Images/GetImagePropertiesController.php index 13c38841..28e641d4 100644 --- a/src/classes/Controllers/Images/GetImagePropertiesController.php +++ b/src/classes/Controllers/Images/GetImagePropertiesController.php @@ -6,15 +6,15 @@ class GetImagePropertiesController { - private $getImageProperties; - + private GetImageProperties $getImageProperties; + public function __construct(GetImageProperties $getImageProperties) { $this->getImageProperties = $getImageProperties; } - public function getAll(Host $host, string $fingerprint) + public function getAll(Host $host, string $fingerprint) :array { return $this->getImageProperties->getAll($host, $fingerprint); } @@ -22,7 +22,7 @@ public function getAll(Host $host, string $fingerprint) /** * This is the list of proprties we support updating for an image */ - public function getFiltertedList(Host $host, string $fingerprint) + public function getFiltertedList(Host $host, string $fingerprint) :array { return $this->getImageProperties->getFiltertedList($host, $fingerprint); } diff --git a/src/classes/Controllers/Images/GetImagesController.php b/src/classes/Controllers/Images/GetImagesController.php index d5a8271c..5db61243 100755 --- a/src/classes/Controllers/Images/GetImagesController.php +++ b/src/classes/Controllers/Images/GetImagesController.php @@ -5,14 +5,14 @@ class GetImagesController { - private $getAllImages; - + private GetAllImages $getAllImages; + public function __construct(GetAllImages $getAllImages) { $this->getAllImages = $getAllImages; } - public function getAllHostImages(int $userId) + public function getAllHostImages(int $userId) :array { return $this->getAllImages->getAllHostImages($userId); } diff --git a/src/classes/Controllers/Images/ImportRemoteImagesController.php b/src/classes/Controllers/Images/ImportRemoteImagesController.php index 5e0639db..c4a49899 100644 --- a/src/classes/Controllers/Images/ImportRemoteImagesController.php +++ b/src/classes/Controllers/Images/ImportRemoteImagesController.php @@ -7,8 +7,8 @@ class ImportRemoteImagesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $importRemoteImagesByFingerprint; - + private ImportRemoteImagesByFingerprint $importRemoteImagesByFingerprint; + public function __construct(ImportRemoteImagesByFingerprint $importRemoteImagesByFingerprint) { $this->importRemoteImagesByFingerprint = $importRemoteImagesByFingerprint; @@ -16,7 +16,7 @@ public function __construct(ImportRemoteImagesByFingerprint $importRemoteImagesB /** * @Route("", name="Import image from simplestream server") */ - public function import(HostsCollection $hosts, array $aliases, $urlKey) + public function import(HostsCollection $hosts, array $aliases, string $urlKey) :array { $operations = $this->importRemoteImagesByFingerprint->import($hosts, $aliases, $urlKey); diff --git a/src/classes/Controllers/Images/Search/SearchController.php b/src/classes/Controllers/Images/Search/SearchController.php index fcfa58a6..8cfee950 100644 --- a/src/classes/Controllers/Images/Search/SearchController.php +++ b/src/classes/Controllers/Images/Search/SearchController.php @@ -3,17 +3,18 @@ namespace dhope0000\LXDClient\Controllers\Images\Search; use dhope0000\LXDClient\Tools\Images\GetAllImages; +use dhope0000\LXDClient\Objects\Host; class SearchController { - private $getAllImages; - + private GetAllImages $getAllImages; + public function __construct(GetAllImages $getAllImages) { $this->getAllImages = $getAllImages; } - public function getAllAvailableImages(int $userId, string $search, string $type = "") + public function getAllAvailableImages(int $userId, string $search, string $type = "") :array { $allImages = $this->getAllImages->getAllHostImages($userId); $output = []; @@ -31,7 +32,7 @@ public function getAllAvailableImages(int $userId, string $search, string $type return $output; } - private function doWork(&$output, &$seenFingerPrints, $images, & $unknownCount, $search, $type, $host) + private function doWork(array &$output, array &$seenFingerPrints, array $images, int &$unknownCount, string $search, string $type, Host $host) :void { foreach ($images as $image) { if (in_array($image["fingerprint"], $seenFingerPrints)) { diff --git a/src/classes/Controllers/Images/SearchRemoteImagesController.php b/src/classes/Controllers/Images/SearchRemoteImagesController.php index ebb0c93c..5f105857 100755 --- a/src/classes/Controllers/Images/SearchRemoteImagesController.php +++ b/src/classes/Controllers/Images/SearchRemoteImagesController.php @@ -6,14 +6,14 @@ class SearchRemoteImagesController { - private $getImages; - + private SearchRemoteImages $getImages; + public function __construct(SearchRemoteImages $searchRemoteImages) { $this->getImages = $searchRemoteImages; } - public function get($urlKey, $searchType, $searchArch) + public function get(string $urlKey, string $searchType, string $searchArch) :array { return $this->getImages->get($urlKey, $searchType, $searchArch); } diff --git a/src/classes/Controllers/Images/UpdateImagePropertiesController.php b/src/classes/Controllers/Images/UpdateImagePropertiesController.php index 581d58e9..a16d25db 100644 --- a/src/classes/Controllers/Images/UpdateImagePropertiesController.php +++ b/src/classes/Controllers/Images/UpdateImagePropertiesController.php @@ -6,8 +6,8 @@ class UpdateImagePropertiesController { - private $updateImageProperties; - + private UpdateImageProperties $updateImageProperties; + public function __construct(UpdateImageProperties $updateImageProperties) { $this->updateImageProperties = $updateImageProperties; @@ -16,7 +16,7 @@ public function __construct(UpdateImageProperties $updateImageProperties) /** * This is the list of proprties we support updating for an image */ - public function update(Host $host, string $fingerprint, array $settings) + public function update(Host $host, string $fingerprint, array $settings) :array { $this->updateImageProperties->update($host, $fingerprint, $settings); return ["state"=>"success", "message"=>"Update image"]; diff --git a/src/classes/Controllers/InstanceSettings/FirstRunController.php b/src/classes/Controllers/InstanceSettings/FirstRunController.php index f364bf40..182511b8 100644 --- a/src/classes/Controllers/InstanceSettings/FirstRunController.php +++ b/src/classes/Controllers/InstanceSettings/FirstRunController.php @@ -8,8 +8,8 @@ class FirstRunController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $firstRun; - private $container; + private FirstRun $firstRun; + private Container $container; public function __construct(FirstRun $firstRun, Container $container) { diff --git a/src/classes/Controllers/InstanceSettings/GetAllSettingsController.php b/src/classes/Controllers/InstanceSettings/GetAllSettingsController.php index 7c00c39c..f55978d1 100644 --- a/src/classes/Controllers/InstanceSettings/GetAllSettingsController.php +++ b/src/classes/Controllers/InstanceSettings/GetAllSettingsController.php @@ -9,10 +9,10 @@ class GetAllSettingsController { - private $getSettings; - private $validatePermissions; - private $dateTools; - + private GetSettings $getSettings; + private ValidatePermissions $validatePermissions; + private DateTools $dateTools; + public function __construct( GetSettings $getSettings, ValidatePermissions $validatePermissions, diff --git a/src/classes/Controllers/InstanceSettings/GetMySettingsOverviewController.php b/src/classes/Controllers/InstanceSettings/GetMySettingsOverviewController.php index 5a512185..74e02b10 100644 --- a/src/classes/Controllers/InstanceSettings/GetMySettingsOverviewController.php +++ b/src/classes/Controllers/InstanceSettings/GetMySettingsOverviewController.php @@ -7,7 +7,7 @@ class GetMySettingsOverviewController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getSettingsOverview; + private GetSettingsOverview $getSettingsOverview; public function __construct(GetSettingsOverview $getSettingsOverview) { diff --git a/src/classes/Controllers/InstanceSettings/Ldap/SaveLdapSettingsController.php b/src/classes/Controllers/InstanceSettings/Ldap/SaveLdapSettingsController.php index cc084776..7251f3be 100644 --- a/src/classes/Controllers/InstanceSettings/Ldap/SaveLdapSettingsController.php +++ b/src/classes/Controllers/InstanceSettings/Ldap/SaveLdapSettingsController.php @@ -7,7 +7,7 @@ class SaveLdapSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $saveLdapSettings; + private SaveLdapSettings $saveLdapSettings; public function __construct(SaveLdapSettings $saveLdapSettings) { @@ -16,7 +16,7 @@ public function __construct(SaveLdapSettings $saveLdapSettings) /** * @Route("", name="Save LXDMosaic Ldap Settings") */ - public function save($userId, $settings) + public function save(int $userId, array $settings) { $this->saveLdapSettings->save($userId, $settings); return ["state"=>"success", "message"=>"Saved Ldap Settings"]; diff --git a/src/classes/Controllers/InstanceSettings/RecordedActions/GetLastController.php b/src/classes/Controllers/InstanceSettings/RecordedActions/GetLastController.php index 705fb2be..0308062e 100644 --- a/src/classes/Controllers/InstanceSettings/RecordedActions/GetLastController.php +++ b/src/classes/Controllers/InstanceSettings/RecordedActions/GetLastController.php @@ -6,7 +6,7 @@ class GetLastController { - private $getActions; + private GetActions $getActions; public function __construct(GetActions $getActions) { diff --git a/src/classes/Controllers/InstanceSettings/SaveAllSettingsController.php b/src/classes/Controllers/InstanceSettings/SaveAllSettingsController.php index b9be2aac..0ec391a5 100644 --- a/src/classes/Controllers/InstanceSettings/SaveAllSettingsController.php +++ b/src/classes/Controllers/InstanceSettings/SaveAllSettingsController.php @@ -7,7 +7,7 @@ class SaveAllSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $saveSettings; + private SaveSettings $saveSettings; public function __construct(SaveSettings $saveSettings) { @@ -16,7 +16,7 @@ public function __construct(SaveSettings $saveSettings) /** * @Route("", name="Save LXDMosaic Settings") */ - public function saveAll($userId, $settings) + public function saveAll(int $userId, array $settings) { $this->saveSettings->save($userId, $settings); return ["state"=>"success", "message"=>"Saved Settings"]; diff --git a/src/classes/Controllers/InstanceSettings/Users/AddUserController.php b/src/classes/Controllers/InstanceSettings/Users/AddUserController.php index 19f5add1..903b0a9c 100644 --- a/src/classes/Controllers/InstanceSettings/Users/AddUserController.php +++ b/src/classes/Controllers/InstanceSettings/Users/AddUserController.php @@ -6,7 +6,7 @@ class AddUserController { - private $addUser; + private AddUser $addUser; public function __construct(AddUser $addUser) { diff --git a/src/classes/Controllers/InstanceSettings/Users/GetUsersController.php b/src/classes/Controllers/InstanceSettings/Users/GetUsersController.php index 2cac6836..b10771f5 100644 --- a/src/classes/Controllers/InstanceSettings/Users/GetUsersController.php +++ b/src/classes/Controllers/InstanceSettings/Users/GetUsersController.php @@ -6,7 +6,7 @@ class GetUsersController { - private $getUsers; + private GetUsers $getUsers; public function __construct(GetUsers $getUsers) { diff --git a/src/classes/Controllers/InstanceSettings/Users/ResetPasswordController.php b/src/classes/Controllers/InstanceSettings/Users/ResetPasswordController.php index b89b1b40..1cb45373 100644 --- a/src/classes/Controllers/InstanceSettings/Users/ResetPasswordController.php +++ b/src/classes/Controllers/InstanceSettings/Users/ResetPasswordController.php @@ -6,7 +6,7 @@ class ResetPasswordController { - private $resetPassword; + private ResetPassword $resetPassword; public function __construct(ResetPassword $resetPassword) { diff --git a/src/classes/Controllers/InstanceSettings/Users/SeachUsersController.php b/src/classes/Controllers/InstanceSettings/Users/SeachUsersController.php index 0e0ad92a..2b4184fb 100644 --- a/src/classes/Controllers/InstanceSettings/Users/SeachUsersController.php +++ b/src/classes/Controllers/InstanceSettings/Users/SeachUsersController.php @@ -6,7 +6,7 @@ class SeachUsersController { - private $searchUsers; + private SearchUsers $searchUsers; public function __construct(SearchUsers $searchUsers) { diff --git a/src/classes/Controllers/Instances/Backups/BackupController.php b/src/classes/Controllers/Instances/Backups/BackupController.php index e8b1d67c..7066c381 100644 --- a/src/classes/Controllers/Instances/Backups/BackupController.php +++ b/src/classes/Controllers/Instances/Backups/BackupController.php @@ -8,7 +8,7 @@ class BackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $backupInstance; + private BackupInstance $backupInstance; public function __construct(BackupInstance $backupInstance) { @@ -21,7 +21,7 @@ public function backup( Host $host, string $container, string $backup, - $wait = true, + bool $wait = true, int $importAndDelete ) { $lxdRespone = $this->backupInstance->create( diff --git a/src/classes/Controllers/Instances/Backups/DeleteBackupController.php b/src/classes/Controllers/Instances/Backups/DeleteBackupController.php index 9ed2e611..bb713499 100644 --- a/src/classes/Controllers/Instances/Backups/DeleteBackupController.php +++ b/src/classes/Controllers/Instances/Backups/DeleteBackupController.php @@ -8,7 +8,7 @@ class DeleteBackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteRemoteBackup; + private DeleteRemoteBackup $deleteRemoteBackup; public function __construct(DeleteRemoteBackup $deleteRemoteBackup) { diff --git a/src/classes/Controllers/Instances/Backups/DeleteLocalBackupController.php b/src/classes/Controllers/Instances/Backups/DeleteLocalBackupController.php index a914af48..84c3f736 100644 --- a/src/classes/Controllers/Instances/Backups/DeleteLocalBackupController.php +++ b/src/classes/Controllers/Instances/Backups/DeleteLocalBackupController.php @@ -8,7 +8,7 @@ class DeleteLocalBackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteLocalBackup; + private DeleteLocalBackup $deleteLocalBackup; public function __construct(DeleteLocalBackup $deleteLocalBackup) { diff --git a/src/classes/Controllers/Instances/Backups/DisableScheduledBackupsController.php b/src/classes/Controllers/Instances/Backups/DisableScheduledBackupsController.php index 731f6df2..3ccec91a 100644 --- a/src/classes/Controllers/Instances/Backups/DisableScheduledBackupsController.php +++ b/src/classes/Controllers/Instances/Backups/DisableScheduledBackupsController.php @@ -8,7 +8,7 @@ class DisableScheduledBackupsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $updateBackupSchedules; + private UpdateBackupSchedules $updateBackupSchedules; public function __construct(UpdateBackupSchedules $updateBackupSchedules) { diff --git a/src/classes/Controllers/Instances/Backups/GetInstanceBackupsController.php b/src/classes/Controllers/Instances/Backups/GetInstanceBackupsController.php index c3801f5a..f48f263e 100644 --- a/src/classes/Controllers/Instances/Backups/GetInstanceBackupsController.php +++ b/src/classes/Controllers/Instances/Backups/GetInstanceBackupsController.php @@ -7,7 +7,7 @@ class GetInstanceBackupsController { - private $getInstanceBackups; + private GetInstanceBackups $getInstanceBackups; public function __construct(GetInstanceBackups $getInstanceBackups) { diff --git a/src/classes/Controllers/Instances/Backups/ImportBackupController.php b/src/classes/Controllers/Instances/Backups/ImportBackupController.php index 683a84ea..aafb914f 100644 --- a/src/classes/Controllers/Instances/Backups/ImportBackupController.php +++ b/src/classes/Controllers/Instances/Backups/ImportBackupController.php @@ -8,8 +8,8 @@ class ImportBackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $storeBackupLocally; - + private StoreBackupLocally $storeBackupLocally; + public function __construct(StoreBackupLocally $storeBackupLocally) { $this->storeBackupLocally = $storeBackupLocally; diff --git a/src/classes/Controllers/Instances/Backups/ScheduleBackupController.php b/src/classes/Controllers/Instances/Backups/ScheduleBackupController.php index 0a948ce5..56babe31 100644 --- a/src/classes/Controllers/Instances/Backups/ScheduleBackupController.php +++ b/src/classes/Controllers/Instances/Backups/ScheduleBackupController.php @@ -8,7 +8,7 @@ class ScheduleBackupController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $addBackupSchedule; + private AddBackupSchedule $addBackupSchedule; public function __construct(AddBackupSchedule $addBackupSchedule) { diff --git a/src/classes/Controllers/Instances/Comments/SetInstanceCommentController.php b/src/classes/Controllers/Instances/Comments/SetInstanceCommentController.php index 74a33183..b19275b3 100644 --- a/src/classes/Controllers/Instances/Comments/SetInstanceCommentController.php +++ b/src/classes/Controllers/Instances/Comments/SetInstanceCommentController.php @@ -7,7 +7,7 @@ class SetInstanceCommentController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $setInstanceComment; + private SetInstanceComment $setInstanceComment; public function __construct(SetInstanceComment $setInstanceComment) { diff --git a/src/classes/Controllers/Instances/CopyInstanceController.php b/src/classes/Controllers/Instances/CopyInstanceController.php index 34aeb9c2..9c9989de 100755 --- a/src/classes/Controllers/Instances/CopyInstanceController.php +++ b/src/classes/Controllers/Instances/CopyInstanceController.php @@ -7,8 +7,8 @@ class CopyInstanceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $copy; - + private Copy $copy; + public function __construct(Copy $copy) { $this->copy = $copy; diff --git a/src/classes/Controllers/Instances/CreateController.php b/src/classes/Controllers/Instances/CreateController.php index 7a7c9e7b..0b93a703 100755 --- a/src/classes/Controllers/Instances/CreateController.php +++ b/src/classes/Controllers/Instances/CreateController.php @@ -9,8 +9,8 @@ class CreateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createInstance; - + private CreateInstance $createInstance; + public function __construct(CreateInstance $createInstance) { $this->createInstance = $createInstance; @@ -19,12 +19,12 @@ public function __construct(CreateInstance $createInstance) * @Route("", name="Create Instance") */ public function create( - $name, - $profileIds = [], + string $name, + array $profileIds = [], HostsCollection $hosts, array $imageDetails, string $instanceType = "", - $server = "", + string $server = "", array $gpus = [], array $config = [], bool $start = false diff --git a/src/classes/Controllers/Instances/CreateImageController.php b/src/classes/Controllers/Instances/CreateImageController.php index b2c4053c..7c43a040 100644 --- a/src/classes/Controllers/Instances/CreateImageController.php +++ b/src/classes/Controllers/Instances/CreateImageController.php @@ -8,8 +8,8 @@ class CreateImageController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createImage; - + private CreateImage $createImage; + public function __construct(CreateImage $createImage) { $this->createImage = $createImage; diff --git a/src/classes/Controllers/Instances/DeleteInstanceController.php b/src/classes/Controllers/Instances/DeleteInstanceController.php index 10b1941b..ecc94a75 100755 --- a/src/classes/Controllers/Instances/DeleteInstanceController.php +++ b/src/classes/Controllers/Instances/DeleteInstanceController.php @@ -7,8 +7,8 @@ class DeleteInstanceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteInstance; - + private DeleteInstance $deleteInstance; + public function __construct(DeleteInstance $deleteInstance) { $this->deleteInstance = $deleteInstance; diff --git a/src/classes/Controllers/Instances/Files/DeletePathController.php b/src/classes/Controllers/Instances/Files/DeletePathController.php index 3175e8bf..d524fafb 100644 --- a/src/classes/Controllers/Instances/Files/DeletePathController.php +++ b/src/classes/Controllers/Instances/Files/DeletePathController.php @@ -8,7 +8,7 @@ class DeletePathController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deletePath; + private DeletePath $deletePath; public function __construct(DeletePath $deletePath) { diff --git a/src/classes/Controllers/Instances/Files/GetPathController.php b/src/classes/Controllers/Instances/Files/GetPathController.php index 130c991b..eb6e7cff 100644 --- a/src/classes/Controllers/Instances/Files/GetPathController.php +++ b/src/classes/Controllers/Instances/Files/GetPathController.php @@ -8,7 +8,7 @@ class GetPathController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getPath; + private GetPath $getPath; public function __construct(GetPath $getPath) { @@ -21,7 +21,7 @@ public function get( Host $host, string $container, string $path, - $download + bool $download ) { return $this->getPath->get($host, $container, $path, (int) $download); } diff --git a/src/classes/Controllers/Instances/Files/UploadFilesToPathController.php b/src/classes/Controllers/Instances/Files/UploadFilesToPathController.php index fca9c3da..af30e158 100644 --- a/src/classes/Controllers/Instances/Files/UploadFilesToPathController.php +++ b/src/classes/Controllers/Instances/Files/UploadFilesToPathController.php @@ -8,7 +8,7 @@ class UploadFilesToPathController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $uploadFiles; + private UploadFiles $uploadFiles; public function __construct(UploadFiles $uploadFiles) { diff --git a/src/classes/Controllers/Instances/GetCurrentInstanceSettingsController.php b/src/classes/Controllers/Instances/GetCurrentInstanceSettingsController.php index 92a5f660..f9544daa 100644 --- a/src/classes/Controllers/Instances/GetCurrentInstanceSettingsController.php +++ b/src/classes/Controllers/Instances/GetCurrentInstanceSettingsController.php @@ -6,8 +6,8 @@ class GetCurrentInstanceSettingsController { - private $getInstanceSettings; - + private GetInstanceSettings $getInstanceSettings; + public function __construct(GetInstanceSettings $getInstanceSettings) { $this->getInstanceSettings = $getInstanceSettings; diff --git a/src/classes/Controllers/Instances/GetInstanceController.php b/src/classes/Controllers/Instances/GetInstanceController.php index d5b8ee77..b1978879 100644 --- a/src/classes/Controllers/Instances/GetInstanceController.php +++ b/src/classes/Controllers/Instances/GetInstanceController.php @@ -6,8 +6,8 @@ class GetInstanceController { - private $getInstance; - + private GetInstance $getInstance; + public function __construct(GetInstance $getInstance) { $this->getInstance = $getInstance; diff --git a/src/classes/Controllers/Instances/InstanceTypes/AddController.php b/src/classes/Controllers/Instances/InstanceTypes/AddController.php index 0f5924f1..f9dda23b 100644 --- a/src/classes/Controllers/Instances/InstanceTypes/AddController.php +++ b/src/classes/Controllers/Instances/InstanceTypes/AddController.php @@ -7,8 +7,8 @@ class AddController { - private $validatePermissions; - private $addInstanceType; + private ValidatePermissions $validatePermissions; + private AddInstanceType $addInstanceType; public function __construct( ValidatePermissions $validatePermissions, diff --git a/src/classes/Controllers/Instances/InstanceTypes/DeleteController.php b/src/classes/Controllers/Instances/InstanceTypes/DeleteController.php index 9985a706..bf751874 100644 --- a/src/classes/Controllers/Instances/InstanceTypes/DeleteController.php +++ b/src/classes/Controllers/Instances/InstanceTypes/DeleteController.php @@ -7,9 +7,9 @@ class DeleteController { - private $validatePermissions; - private $deleteInstanceType; - + private ValidatePermissions $validatePermissions; + private DeleteInstanceType $deleteInstanceType; + public function __construct( ValidatePermissions $validatePermissions, DeleteInstanceType $deleteInstanceType diff --git a/src/classes/Controllers/Instances/InstanceTypes/Providers/AddController.php b/src/classes/Controllers/Instances/InstanceTypes/Providers/AddController.php index b72ca2b7..3b83b3cf 100644 --- a/src/classes/Controllers/Instances/InstanceTypes/Providers/AddController.php +++ b/src/classes/Controllers/Instances/InstanceTypes/Providers/AddController.php @@ -8,9 +8,9 @@ class AddController { - private $validatePermissions; - private $addProvider; - private $container; + private ValidatePermissions $validatePermissions; + private AddProvider $addProvider; + private Container $container; public function __construct( Container $container, diff --git a/src/classes/Controllers/Instances/InstanceTypes/Providers/RemoveController.php b/src/classes/Controllers/Instances/InstanceTypes/Providers/RemoveController.php index 5883cfa0..0adaf508 100644 --- a/src/classes/Controllers/Instances/InstanceTypes/Providers/RemoveController.php +++ b/src/classes/Controllers/Instances/InstanceTypes/Providers/RemoveController.php @@ -8,9 +8,9 @@ class RemoveController { - private $validatePermissions; - private $removeProvider; - private $container; + private ValidatePermissions $validatePermissions; + private RemoveProvider $removeProvider; + private Container $container; public function __construct( Container $container, diff --git a/src/classes/Controllers/Instances/Metrics/DisablePullGatheringController.php b/src/classes/Controllers/Instances/Metrics/DisablePullGatheringController.php index 005ccb36..fda39ac7 100644 --- a/src/classes/Controllers/Instances/Metrics/DisablePullGatheringController.php +++ b/src/classes/Controllers/Instances/Metrics/DisablePullGatheringController.php @@ -7,8 +7,8 @@ class DisablePullGatheringController { - private $disablePullGathering; - + private DisablePullGathering $disablePullGathering; + public function __construct(DisablePullGathering $disablePullGathering) { $this->disablePullGathering = $disablePullGathering; diff --git a/src/classes/Controllers/Instances/Metrics/EnablePullGatheringController.php b/src/classes/Controllers/Instances/Metrics/EnablePullGatheringController.php index ab528d4d..baf0650a 100644 --- a/src/classes/Controllers/Instances/Metrics/EnablePullGatheringController.php +++ b/src/classes/Controllers/Instances/Metrics/EnablePullGatheringController.php @@ -7,8 +7,8 @@ class EnablePullGatheringController { - private $enablePullGathering; - + private EnablePullGathering $enablePullGathering; + public function __construct(EnablePullGathering $enablePullGathering) { $this->enablePullGathering = $enablePullGathering; diff --git a/src/classes/Controllers/Instances/Metrics/GetAllAvailableMetricsController.php b/src/classes/Controllers/Instances/Metrics/GetAllAvailableMetricsController.php index 49e515b4..a2a7c8d5 100644 --- a/src/classes/Controllers/Instances/Metrics/GetAllAvailableMetricsController.php +++ b/src/classes/Controllers/Instances/Metrics/GetAllAvailableMetricsController.php @@ -6,8 +6,8 @@ class GetAllAvailableMetricsController { - private $getAvailableHostsMetrics; - + private GetAvailableHostsMetrics $getAvailableHostsMetrics; + public function __construct(GetAvailableHostsMetrics $getAvailableHostsMetrics) { $this->getAvailableHostsMetrics = $getAvailableHostsMetrics; diff --git a/src/classes/Controllers/Instances/Metrics/GetGraphDataController.php b/src/classes/Controllers/Instances/Metrics/GetGraphDataController.php index 44dc75e4..e796ed27 100644 --- a/src/classes/Controllers/Instances/Metrics/GetGraphDataController.php +++ b/src/classes/Controllers/Instances/Metrics/GetGraphDataController.php @@ -6,8 +6,8 @@ class GetGraphDataController { - private $getMetricsForContainer; - + private GetMetricsForContainer $getMetricsForContainer; + public function __construct(GetMetricsForContainer $getMetricsForContainer) { $this->getMetricsForContainer = $getMetricsForContainer; diff --git a/src/classes/Controllers/Instances/MigrateInstanceController.php b/src/classes/Controllers/Instances/MigrateInstanceController.php index 864b6ce9..0209d8f8 100755 --- a/src/classes/Controllers/Instances/MigrateInstanceController.php +++ b/src/classes/Controllers/Instances/MigrateInstanceController.php @@ -7,8 +7,8 @@ class MigrateInstanceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $migrate; - + private Migrate $migrate; + public function __construct(Migrate $migrate) { $this->migrate = $migrate; @@ -16,7 +16,7 @@ public function __construct(Migrate $migrate) /** * @Route("", name="Migrate Instance") */ - public function migrate(Host $hostId, $container, Host $destination) + public function migrate(Host $hostId, string $container, Host $destination) { $this->migrate->migrate($hostId, $container, $destination, $container, true); return array("success"=>"Instance Has Been Migrated"); diff --git a/src/classes/Controllers/Instances/Profiles/AssignProfilesController.php b/src/classes/Controllers/Instances/Profiles/AssignProfilesController.php index 27bc02c2..61c806f4 100644 --- a/src/classes/Controllers/Instances/Profiles/AssignProfilesController.php +++ b/src/classes/Controllers/Instances/Profiles/AssignProfilesController.php @@ -7,8 +7,8 @@ class AssignProfilesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $assignProfiles; - + private AssignProfiles $assignProfiles; + public function __construct(AssignProfiles $assignProfiles) { $this->assignProfiles = $assignProfiles; diff --git a/src/classes/Controllers/Instances/Profiles/RemoveProfileController.php b/src/classes/Controllers/Instances/Profiles/RemoveProfileController.php index e1419b98..98967379 100644 --- a/src/classes/Controllers/Instances/Profiles/RemoveProfileController.php +++ b/src/classes/Controllers/Instances/Profiles/RemoveProfileController.php @@ -7,8 +7,8 @@ class RemoveProfileController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $removeProfiles; - + private RemoveProfiles $removeProfiles; + public function __construct(RemoveProfiles $removeProfiles) { $this->removeProfiles = $removeProfiles; diff --git a/src/classes/Controllers/Instances/RecordedActions/GetHostInstanceEventsController.php b/src/classes/Controllers/Instances/RecordedActions/GetHostInstanceEventsController.php index 4bf0853f..50d36304 100644 --- a/src/classes/Controllers/Instances/RecordedActions/GetHostInstanceEventsController.php +++ b/src/classes/Controllers/Instances/RecordedActions/GetHostInstanceEventsController.php @@ -8,8 +8,8 @@ class GetHostInstanceEventsController { - private $getAllInstanceRecordedActions; - + private GetAllInstanceRecordedActions $getAllInstanceRecordedActions; + public function __construct(GetAllInstanceRecordedActions $getAllInstanceRecordedActions) { $this->getAllInstanceRecordedActions = $getAllInstanceRecordedActions; diff --git a/src/classes/Controllers/Instances/RenameInstanceController.php b/src/classes/Controllers/Instances/RenameInstanceController.php index 83b26abb..494199f1 100755 --- a/src/classes/Controllers/Instances/RenameInstanceController.php +++ b/src/classes/Controllers/Instances/RenameInstanceController.php @@ -7,7 +7,7 @@ class RenameInstanceController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $renameInstance; + private RenameInstance $renameInstance; public function __construct(RenameInstance $renameInstance) { diff --git a/src/classes/Controllers/Instances/SetSettingsController.php b/src/classes/Controllers/Instances/SetSettingsController.php index b0f4678c..9376b792 100644 --- a/src/classes/Controllers/Instances/SetSettingsController.php +++ b/src/classes/Controllers/Instances/SetSettingsController.php @@ -7,7 +7,7 @@ class SetSettingsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $setInstanceSettings; + private SetInstanceSettings $setInstanceSettings; public function __construct(SetInstanceSettings $setInstanceSettings) { diff --git a/src/classes/Controllers/Instances/Settings/GetAllAvailableSettingsController.php b/src/classes/Controllers/Instances/Settings/GetAllAvailableSettingsController.php index c50a6e01..aad00345 100644 --- a/src/classes/Controllers/Instances/Settings/GetAllAvailableSettingsController.php +++ b/src/classes/Controllers/Instances/Settings/GetAllAvailableSettingsController.php @@ -5,8 +5,8 @@ class GetAllAvailableSettingsController { - private $getSettings; - + private GetSettings $getSettings; + public function __construct(GetSettings $getSettings) { $this->getSettings = $getSettings; diff --git a/src/classes/Controllers/Instances/Snapshot/DeleteSnapshotController.php b/src/classes/Controllers/Instances/Snapshot/DeleteSnapshotController.php index d0c48172..25d10343 100755 --- a/src/classes/Controllers/Instances/Snapshot/DeleteSnapshotController.php +++ b/src/classes/Controllers/Instances/Snapshot/DeleteSnapshotController.php @@ -7,8 +7,8 @@ class DeleteSnapshotController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteSnapshot; - + private DeleteSnapshot $deleteSnapshot; + public function __construct(DeleteSnapshot $deleteSnapshot) { $this->deleteSnapshot = $deleteSnapshot; diff --git a/src/classes/Controllers/Instances/Snapshot/GetSnapshotsOverviewController.php b/src/classes/Controllers/Instances/Snapshot/GetSnapshotsOverviewController.php index 436f6fb6..daea5120 100644 --- a/src/classes/Controllers/Instances/Snapshot/GetSnapshotsOverviewController.php +++ b/src/classes/Controllers/Instances/Snapshot/GetSnapshotsOverviewController.php @@ -7,7 +7,7 @@ class GetSnapshotsOverviewController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getSnapshotsOverview; + private GetSnapshotsOverview $getSnapshotsOverview; public function __construct(GetSnapshotsOverview $getSnapshotsOverview) { diff --git a/src/classes/Controllers/Instances/Snapshot/RenameSnapshotController.php b/src/classes/Controllers/Instances/Snapshot/RenameSnapshotController.php index dfe156dc..4b60c737 100644 --- a/src/classes/Controllers/Instances/Snapshot/RenameSnapshotController.php +++ b/src/classes/Controllers/Instances/Snapshot/RenameSnapshotController.php @@ -7,8 +7,8 @@ class RenameSnapshotController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $renameSnapshot; - + private RenameSnapshot $renameSnapshot; + public function __construct(RenameSnapshot $renameSnapshot) { $this->renameSnapshot = $renameSnapshot; diff --git a/src/classes/Controllers/Instances/Snapshot/RestoreSnapshotController.php b/src/classes/Controllers/Instances/Snapshot/RestoreSnapshotController.php index f5e19be2..0b9c52c5 100755 --- a/src/classes/Controllers/Instances/Snapshot/RestoreSnapshotController.php +++ b/src/classes/Controllers/Instances/Snapshot/RestoreSnapshotController.php @@ -8,8 +8,8 @@ class RestoreSnapshotController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $restoreSnapshot; - + private RestoreSnapshot $restoreSnapshot; + public function __construct(RestoreSnapshot $restoreSnapshot) { $this->restoreSnapshot = $restoreSnapshot; diff --git a/src/classes/Controllers/Instances/Snapshot/ScheduleSnapshotsController.php b/src/classes/Controllers/Instances/Snapshot/ScheduleSnapshotsController.php index 31b133de..f7877fff 100644 --- a/src/classes/Controllers/Instances/Snapshot/ScheduleSnapshotsController.php +++ b/src/classes/Controllers/Instances/Snapshot/ScheduleSnapshotsController.php @@ -7,7 +7,7 @@ class ScheduleSnapshotsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $scheduleSnapshots; + private ScheduleSnapshots $scheduleSnapshots; public function __construct(ScheduleSnapshots $scheduleSnapshots) { diff --git a/src/classes/Controllers/Instances/Snapshot/TakeSnapshotController.php b/src/classes/Controllers/Instances/Snapshot/TakeSnapshotController.php index c2a537f0..62612c10 100755 --- a/src/classes/Controllers/Instances/Snapshot/TakeSnapshotController.php +++ b/src/classes/Controllers/Instances/Snapshot/TakeSnapshotController.php @@ -7,8 +7,8 @@ class TakeSnapshotController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $takeSnapshot; - + private TakeSnapshot $takeSnapshot; + public function __construct(TakeSnapshot $takeSnapshot) { $this->takeSnapshot = $takeSnapshot; diff --git a/src/classes/Controllers/Instances/StateController.php b/src/classes/Controllers/Instances/StateController.php index 091ff518..0e7d64f1 100755 --- a/src/classes/Controllers/Instances/StateController.php +++ b/src/classes/Controllers/Instances/StateController.php @@ -8,8 +8,8 @@ class StateController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $state; - + private State $state; + public function __construct(State $state) { $this->state = $state; @@ -17,7 +17,7 @@ public function __construct(State $state) /** * @Route("", name="Start Instance") */ - public function start(Host $host, $container) + public function start(Host $host, string $container) :array { $this->state->change($host, $container, StateCon::START); return ["state"=>"success", "message"=>"Starting {$host->getAlias()}/$container", "code"=>101]; @@ -25,7 +25,7 @@ public function start(Host $host, $container) /** * @Route("", name="Stop Instance") */ - public function stop(Host $host, $container) + public function stop(Host $host, string $container) :array { $this->state->change($host, $container, StateCon::STOP); return ["state"=>"success", "message"=>"Stopping {$host->getAlias()}alias/$container", "code"=>102]; @@ -33,7 +33,7 @@ public function stop(Host $host, $container) /** * @Route("", name="Restart Instance") */ - public function restart(Host $host, $container) + public function restart(Host $host, string $container) :array { $this->state->change($host, $container, StateCon::RESTART); return ["state"=>"success", "message"=>"Restarting {$host->getAlias()}/$container", "code"=>101]; @@ -41,7 +41,7 @@ public function restart(Host $host, $container) /** * @Route("", name="Freeze Instance") */ - public function freeze(Host $host, $container) + public function freeze(Host $host, string $container) :array { $this->state->change($host, $container, StateCon::FREEZE); return ["state"=>"success", "message"=>"Freezing {$host->getAlias()}/$container", "code"=>110]; @@ -49,7 +49,7 @@ public function freeze(Host $host, $container) /** * @Route("", name="UnFreeze Instance") */ - public function unfreeze(Host $host, $container) + public function unfreeze(Host $host, string $container) :array { $this->state->change($host, $container, StateCon::UNFREEZE); return ["state"=>"success", "message"=>"Unfreezing {$host->getAlias()}/$container", "code"=>101]; diff --git a/src/classes/Controllers/Instances/VirtualMachines/CreateController.php b/src/classes/Controllers/Instances/VirtualMachines/CreateController.php index 6ee74948..47c79caa 100644 --- a/src/classes/Controllers/Instances/VirtualMachines/CreateController.php +++ b/src/classes/Controllers/Instances/VirtualMachines/CreateController.php @@ -7,8 +7,8 @@ class CreateController { - private $createVirutalMachine; - + private CreateVirutalMachine $createVirutalMachine; + public function __construct(CreateVirutalMachine $createVirutalMachine) { $this->createVirutalMachine = $createVirutalMachine; diff --git a/src/classes/Controllers/Instances/Volumes/AttachVolumesController.php b/src/classes/Controllers/Instances/Volumes/AttachVolumesController.php index c759227c..692c016c 100644 --- a/src/classes/Controllers/Instances/Volumes/AttachVolumesController.php +++ b/src/classes/Controllers/Instances/Volumes/AttachVolumesController.php @@ -7,7 +7,7 @@ class AttachVolumesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $attachVolumes; + private AttachVolumes $attachVolumes; public function __construct(AttachVolumes $attachVolumes) { diff --git a/src/classes/Controllers/Networks/CreateNetworkController.php b/src/classes/Controllers/Networks/CreateNetworkController.php index f2855988..8a8df41b 100644 --- a/src/classes/Controllers/Networks/CreateNetworkController.php +++ b/src/classes/Controllers/Networks/CreateNetworkController.php @@ -8,7 +8,7 @@ class CreateNetworkController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createNetwork; + private CreateNetwork $createNetwork; public function __construct(CreateNetwork $createNetwork) { @@ -17,7 +17,7 @@ public function __construct(CreateNetwork $createNetwork) /** * @Route("", name="Create Network") */ - public function create(HostsCollection $hosts, string $name, string $description = "", array $config = []) + public function create(HostsCollection $hosts, string $name, string $description = "", array $config = []) :array { $this->createNetwork->create($hosts, $name, $description, $config); return ["state"=>"success", "message"=>"Created network"]; diff --git a/src/classes/Controllers/Networks/DeleteNetworkController.php b/src/classes/Controllers/Networks/DeleteNetworkController.php index 9fd10df4..d970ba98 100644 --- a/src/classes/Controllers/Networks/DeleteNetworkController.php +++ b/src/classes/Controllers/Networks/DeleteNetworkController.php @@ -8,8 +8,8 @@ class DeleteNetworkController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteNetwork; - + private DeleteNetwork $deleteNetwork; + public function __construct(DeleteNetwork $deleteNetwork) { $this->deleteNetwork = $deleteNetwork; @@ -17,7 +17,7 @@ public function __construct(DeleteNetwork $deleteNetwork) /** * @Route("", name="Delete Network") */ - public function delete(Host $host, $network) + public function delete(Host $host, string $network) :array { $this->deleteNetwork->delete($host, $network); return ["state"=>"success", "message"=>"Deleted network"]; diff --git a/src/classes/Controllers/Networks/GetHostsNetworksController.php b/src/classes/Controllers/Networks/GetHostsNetworksController.php index 17b285c0..ab6151c7 100644 --- a/src/classes/Controllers/Networks/GetHostsNetworksController.php +++ b/src/classes/Controllers/Networks/GetHostsNetworksController.php @@ -6,14 +6,14 @@ class GetHostsNetworksController { - private $getHostsNetworks; - + private GetHostsNetworks $getHostsNetworks; + public function __construct(GetHostsNetworks $getHostsNetworks) { $this->getHostsNetworks = $getHostsNetworks; } - public function get(int $userId) + public function get(int $userId) :array { return $this->getHostsNetworks->getAll($userId); } diff --git a/src/classes/Controllers/Networks/GetNetworkController.php b/src/classes/Controllers/Networks/GetNetworkController.php index fbd8094c..1fdddacd 100644 --- a/src/classes/Controllers/Networks/GetNetworkController.php +++ b/src/classes/Controllers/Networks/GetNetworkController.php @@ -7,14 +7,14 @@ class GetNetworkController { - private $getNetwork; - + private GetNetwork $getNetwork; + public function __construct(GetNetwork $getNetwork) { $this->getNetwork = $getNetwork; } - public function get(int $userId, Host $host, $network) + public function get(int $userId, Host $host, string $network) :array { return $this->getNetwork->get($userId, $host, $network); } diff --git a/src/classes/Controllers/Networks/GetNetworksDashboardController.php b/src/classes/Controllers/Networks/GetNetworksDashboardController.php index 2eecb6fc..cc92b8fd 100644 --- a/src/classes/Controllers/Networks/GetNetworksDashboardController.php +++ b/src/classes/Controllers/Networks/GetNetworksDashboardController.php @@ -6,14 +6,14 @@ class GetNetworksDashboardController { - private $getNetworksDashboard; - + private GetNetworksDashboard $getNetworksDashboard; + public function __construct(GetNetworksDashboard $getNetworksDashboard) { $this->getNetworksDashboard = $getNetworksDashboard; } - public function get(int $userId) + public function get(int $userId) :array { return $this->getNetworksDashboard->get($userId); } diff --git a/src/classes/Controllers/Networks/Tools/FindIpAddressController.php b/src/classes/Controllers/Networks/Tools/FindIpAddressController.php index 25575cc0..6a46ff9d 100644 --- a/src/classes/Controllers/Networks/Tools/FindIpAddressController.php +++ b/src/classes/Controllers/Networks/Tools/FindIpAddressController.php @@ -7,8 +7,8 @@ class FindIpAddressController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $findIpAddress; - + private FindIpAddress $findIpAddress; + public function __construct(FindIpAddress $findIpAddress) { $this->findIpAddress = $findIpAddress; @@ -16,7 +16,7 @@ public function __construct(FindIpAddress $findIpAddress) /** * @Route("", name="Find instance ip address") */ - public function find(string $ip) + public function find(string $ip) :array { $result = $this->findIpAddress->find($ip); return ["state"=>"success", "result"=>$result]; diff --git a/src/classes/Controllers/Profiles/CopyProfileController.php b/src/classes/Controllers/Profiles/CopyProfileController.php index 10ee6e8f..2aa8d8b4 100644 --- a/src/classes/Controllers/Profiles/CopyProfileController.php +++ b/src/classes/Controllers/Profiles/CopyProfileController.php @@ -8,8 +8,8 @@ class CopyProfileController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $copy; - + private Copy $copy; + public function __construct(Copy $copy) { $this->copy = $copy; diff --git a/src/classes/Controllers/Profiles/CreateProfileController.php b/src/classes/Controllers/Profiles/CreateProfileController.php index 67e53594..b1ff54b0 100644 --- a/src/classes/Controllers/Profiles/CreateProfileController.php +++ b/src/classes/Controllers/Profiles/CreateProfileController.php @@ -1,14 +1,13 @@ deleteProfile = $deleteProfile; diff --git a/src/classes/Controllers/Profiles/GetAllProfilesController.php b/src/classes/Controllers/Profiles/GetAllProfilesController.php index b7cfa766..abe73613 100755 --- a/src/classes/Controllers/Profiles/GetAllProfilesController.php +++ b/src/classes/Controllers/Profiles/GetAllProfilesController.php @@ -5,8 +5,8 @@ class GetAllProfilesController { - private $universe; - + private Universe $universe; + public function __construct(Universe $universe) { $this->universe = $universe; diff --git a/src/classes/Controllers/Profiles/GetProfileController.php b/src/classes/Controllers/Profiles/GetProfileController.php index 6ec2d73c..69b00cf3 100644 --- a/src/classes/Controllers/Profiles/GetProfileController.php +++ b/src/classes/Controllers/Profiles/GetProfileController.php @@ -7,8 +7,8 @@ class GetProfileController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getProfile; - + private GetProfile $getProfile; + public function __construct(GetProfile $getProfile) { $this->getProfile = $getProfile; diff --git a/src/classes/Controllers/Profiles/GetProfilesDashboardController.php b/src/classes/Controllers/Profiles/GetProfilesDashboardController.php index ceba4e19..f4b20e1e 100644 --- a/src/classes/Controllers/Profiles/GetProfilesDashboardController.php +++ b/src/classes/Controllers/Profiles/GetProfilesDashboardController.php @@ -7,7 +7,7 @@ class GetProfilesDashboardController { - private $getProfilesDashboard; + private GetProfilesDashboard $getProfilesDashboard; public function __construct(GetProfilesDashboard $getProfilesDashboard) { diff --git a/src/classes/Controllers/Profiles/RenameProfileController.php b/src/classes/Controllers/Profiles/RenameProfileController.php index 0534b1f4..4346ef56 100644 --- a/src/classes/Controllers/Profiles/RenameProfileController.php +++ b/src/classes/Controllers/Profiles/RenameProfileController.php @@ -7,8 +7,8 @@ class RenameProfileController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $rename; - + private Rename $rename; + public function __construct(Rename $rename) { $this->rename = $rename; diff --git a/src/classes/Controllers/Profiles/ReplaceProfileController.php b/src/classes/Controllers/Profiles/ReplaceProfileController.php index 0427ab09..451300a8 100644 --- a/src/classes/Controllers/Profiles/ReplaceProfileController.php +++ b/src/classes/Controllers/Profiles/ReplaceProfileController.php @@ -1,18 +1,11 @@ rename = $rename; - } /** * @Route("", name="Replace Profile") */ diff --git a/src/classes/Controllers/Profiles/Search/SearchProfiles.php b/src/classes/Controllers/Profiles/Search/SearchProfiles.php index f82ee483..ce5ac3b2 100644 --- a/src/classes/Controllers/Profiles/Search/SearchProfiles.php +++ b/src/classes/Controllers/Profiles/Search/SearchProfiles.php @@ -6,8 +6,8 @@ class SearchProfiles { - private $getProfilesOnAllHosts; - + private GetProfilesOnAllHosts $getProfilesOnAllHosts; + public function __construct(GetProfilesOnAllHosts $getProfilesOnAllHosts) { $this->getProfilesOnAllHosts = $getProfilesOnAllHosts; diff --git a/src/classes/Controllers/ProjectAnalytics/GetGraphableProjectAnalyticsController.php b/src/classes/Controllers/ProjectAnalytics/GetGraphableProjectAnalyticsController.php index c0400302..8ea8300f 100644 --- a/src/classes/Controllers/ProjectAnalytics/GetGraphableProjectAnalyticsController.php +++ b/src/classes/Controllers/ProjectAnalytics/GetGraphableProjectAnalyticsController.php @@ -8,8 +8,8 @@ class GetGraphableProjectAnalyticsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getGraphableProjectAnalytics; - + private GetGraphableProjectAnalytics $getGraphableProjectAnalytics; + public function __construct(GetGraphableProjectAnalytics $getGraphableProjectAnalytics) { $this->getGraphableProjectAnalytics = $getGraphableProjectAnalytics; diff --git a/src/classes/Controllers/Projects/CreateProjectController.php b/src/classes/Controllers/Projects/CreateProjectController.php index 4ef63db0..b621c9c6 100644 --- a/src/classes/Controllers/Projects/CreateProjectController.php +++ b/src/classes/Controllers/Projects/CreateProjectController.php @@ -9,9 +9,9 @@ class CreateProjectController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $validatePermissions; - private $createProject; - + private ValidatePermissions $validatePermissions; + private CreateProject $createProject; + public function __construct(ValidatePermissions $validatePermissions, CreateProject $createProject) { $this->validatePermissions = $validatePermissions; diff --git a/src/classes/Controllers/Projects/DeleteProjectController.php b/src/classes/Controllers/Projects/DeleteProjectController.php index 3c801184..402bcbb6 100644 --- a/src/classes/Controllers/Projects/DeleteProjectController.php +++ b/src/classes/Controllers/Projects/DeleteProjectController.php @@ -8,8 +8,8 @@ class DeleteProjectController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteProject; - + private DeleteProject $deleteProject; + public function __construct(DeleteProject $deleteProject) { $this->deleteProject = $deleteProject; diff --git a/src/classes/Controllers/Projects/GetHostsProjectsController.php b/src/classes/Controllers/Projects/GetHostsProjectsController.php index a01bdb25..2dcda114 100644 --- a/src/classes/Controllers/Projects/GetHostsProjectsController.php +++ b/src/classes/Controllers/Projects/GetHostsProjectsController.php @@ -2,13 +2,12 @@ namespace dhope0000\LXDClient\Controllers\Projects; -use dhope0000\LXDClient\Tools\Projects\CreateProject; use dhope0000\LXDClient\Tools\Projects\GetHostsProjects; class GetHostsProjectsController { - private $getHostsProjects; - + private GetHostsProjects $getHostsProjects; + public function __construct(GetHostsProjects $getHostsProjects) { $this->getHostsProjects = $getHostsProjects; diff --git a/src/classes/Controllers/Projects/GetHostsProjectsOverviewController.php b/src/classes/Controllers/Projects/GetHostsProjectsOverviewController.php index 9cec5567..c333234c 100644 --- a/src/classes/Controllers/Projects/GetHostsProjectsOverviewController.php +++ b/src/classes/Controllers/Projects/GetHostsProjectsOverviewController.php @@ -6,7 +6,7 @@ class GetHostsProjectsOverviewController { - private $getHostProjectsOverview; + private GetHostProjectsOverview $getHostProjectsOverview; public function __construct(GetHostProjectsOverview $getHostProjectsOverview) { diff --git a/src/classes/Controllers/Projects/GetProjectInfoController.php b/src/classes/Controllers/Projects/GetProjectInfoController.php index 05e5bc94..49077563 100644 --- a/src/classes/Controllers/Projects/GetProjectInfoController.php +++ b/src/classes/Controllers/Projects/GetProjectInfoController.php @@ -7,8 +7,8 @@ class GetProjectInfoController { - private $getProjectInfo; - + private GetProjectInfo $getProjectInfo; + public function __construct(GetProjectInfo $getProjectInfo) { $this->getProjectInfo = $getProjectInfo; diff --git a/src/classes/Controllers/Projects/GetProjectsOverviewController.php b/src/classes/Controllers/Projects/GetProjectsOverviewController.php index ea2a5b1e..04be855e 100644 --- a/src/classes/Controllers/Projects/GetProjectsOverviewController.php +++ b/src/classes/Controllers/Projects/GetProjectsOverviewController.php @@ -7,8 +7,8 @@ class GetProjectsOverviewController { - private $getProjectsOverview; - + private GetProjectsOverview $getProjectsOverview; + public function __construct(GetProjectsOverview $getProjectsOverview) { $this->getProjectsOverview = $getProjectsOverview; diff --git a/src/classes/Controllers/Projects/RenameProjectController.php b/src/classes/Controllers/Projects/RenameProjectController.php index ad02facb..ecdcf05b 100644 --- a/src/classes/Controllers/Projects/RenameProjectController.php +++ b/src/classes/Controllers/Projects/RenameProjectController.php @@ -8,8 +8,8 @@ class RenameProjectController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $renameProject; - + private RenameProject $renameProject; + public function __construct(RenameProject $renameProject) { $this->renameProject = $renameProject; diff --git a/src/classes/Controllers/Projects/Search/GetCommonToHostsProjectsController.php b/src/classes/Controllers/Projects/Search/GetCommonToHostsProjectsController.php index ab71804c..41ec6d9e 100644 --- a/src/classes/Controllers/Projects/Search/GetCommonToHostsProjectsController.php +++ b/src/classes/Controllers/Projects/Search/GetCommonToHostsProjectsController.php @@ -8,8 +8,8 @@ class GetCommonToHostsProjectsController { - private $getCommonToHostsProjects; - + private GetCommonToHostsProjects $getCommonToHostsProjects; + public function __construct(GetCommonToHostsProjects $getCommonToHostsProjects) { $this->getCommonToHostsProjects = $getCommonToHostsProjects; diff --git a/src/classes/Controllers/Projects/Users/GetUsersWithAccessController.php b/src/classes/Controllers/Projects/Users/GetUsersWithAccessController.php index 63307119..0210ca92 100644 --- a/src/classes/Controllers/Projects/Users/GetUsersWithAccessController.php +++ b/src/classes/Controllers/Projects/Users/GetUsersWithAccessController.php @@ -8,8 +8,8 @@ class GetUsersWithAccessController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getUsersAccessToProject; - + private GetUsersAccessToProject $getUsersAccessToProject; + public function __construct(GetUsersAccessToProject $getUsersAccessToProject) { $this->getUsersAccessToProject = $getUsersAccessToProject; diff --git a/src/classes/Controllers/Storage/CreatePoolController.php b/src/classes/Controllers/Storage/CreatePoolController.php index 3aa4d9c1..45101f00 100644 --- a/src/classes/Controllers/Storage/CreatePoolController.php +++ b/src/classes/Controllers/Storage/CreatePoolController.php @@ -8,8 +8,8 @@ class CreatePoolController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createStoragePool; - + private CreateStoragePool $createStoragePool; + public function __construct(CreateStoragePool $createStoragePool) { $this->createStoragePool = $createStoragePool; diff --git a/src/classes/Controllers/Storage/DeleteStoragePoolController.php b/src/classes/Controllers/Storage/DeleteStoragePoolController.php index fd370750..9c73633d 100644 --- a/src/classes/Controllers/Storage/DeleteStoragePoolController.php +++ b/src/classes/Controllers/Storage/DeleteStoragePoolController.php @@ -8,8 +8,8 @@ class DeleteStoragePoolController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteStoragePool; - + private DeleteStoragePool $deleteStoragePool; + public function __construct(DeleteStoragePool $deleteStoragePool) { $this->deleteStoragePool = $deleteStoragePool; diff --git a/src/classes/Controllers/Storage/GetHostsStorageController.php b/src/classes/Controllers/Storage/GetHostsStorageController.php index 034de16f..162c3688 100644 --- a/src/classes/Controllers/Storage/GetHostsStorageController.php +++ b/src/classes/Controllers/Storage/GetHostsStorageController.php @@ -6,14 +6,14 @@ class GetHostsStorageController { - private $getUserStorage; - + private GetUserStorage $getUserStorage; + public function __construct(GetUserStorage $getUserStorage) { $this->getUserStorage = $getUserStorage; } - public function get($userId) + public function get(int $userId) { return $this->getUserStorage->getAll($userId); } diff --git a/src/classes/Controllers/Storage/GetHostsStoragePoolController.php b/src/classes/Controllers/Storage/GetHostsStoragePoolController.php index 4b47f0a1..679c96df 100644 --- a/src/classes/Controllers/Storage/GetHostsStoragePoolController.php +++ b/src/classes/Controllers/Storage/GetHostsStoragePoolController.php @@ -7,8 +7,8 @@ class GetHostsStoragePoolController { - private $getStoragePool; - + private GetStoragePool $getStoragePool; + public function __construct(GetStoragePool $getStoragePool) { $this->getStoragePool = $getStoragePool; diff --git a/src/classes/Controllers/Storage/Volumes/CreateStorageVolumeController.php b/src/classes/Controllers/Storage/Volumes/CreateStorageVolumeController.php index 20d27e39..777577aa 100644 --- a/src/classes/Controllers/Storage/Volumes/CreateStorageVolumeController.php +++ b/src/classes/Controllers/Storage/Volumes/CreateStorageVolumeController.php @@ -8,8 +8,8 @@ class CreateStorageVolumeController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $createVolume; - + private CreateVolume $createVolume; + public function __construct(CreateVolume $createVolume) { $this->createVolume = $createVolume; @@ -17,7 +17,7 @@ public function __construct(CreateVolume $createVolume) /** * @Route("", name="Create storage volume") */ - public function create(Host $hostId, string $pool, string $name, array $config) + public function create(Host $hostId, string $pool, string $name, array $config) :array { $this->createVolume->create($hostId, $pool, $name, $config); return ["state"=>"success", "message"=>"Created Volume"]; diff --git a/src/classes/Controllers/Storage/Volumes/DeleteStorageVolumeController.php b/src/classes/Controllers/Storage/Volumes/DeleteStorageVolumeController.php index b6941acc..daa105f6 100644 --- a/src/classes/Controllers/Storage/Volumes/DeleteStorageVolumeController.php +++ b/src/classes/Controllers/Storage/Volumes/DeleteStorageVolumeController.php @@ -8,8 +8,8 @@ class DeleteStorageVolumeController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteVolume; - + private DeleteVolume $deleteVolume; + public function __construct(DeleteVolume $deleteVolume) { $this->deleteVolume = $deleteVolume; diff --git a/src/classes/Controllers/Storage/Volumes/GetHostStorageVolumesController.php b/src/classes/Controllers/Storage/Volumes/GetHostStorageVolumesController.php index 02b879c4..cfb00399 100644 --- a/src/classes/Controllers/Storage/Volumes/GetHostStorageVolumesController.php +++ b/src/classes/Controllers/Storage/Volumes/GetHostStorageVolumesController.php @@ -8,8 +8,8 @@ class GetHostStorageVolumesController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getVolumes; - + private GetVolumes $getVolumes; + public function __construct(GetVolumes $getVolumes) { $this->getVolumes = $getVolumes; diff --git a/src/classes/Controllers/Storage/Volumes/GetStorageVolumeController.php b/src/classes/Controllers/Storage/Volumes/GetStorageVolumeController.php index c042c6c4..c53e36bc 100644 --- a/src/classes/Controllers/Storage/Volumes/GetStorageVolumeController.php +++ b/src/classes/Controllers/Storage/Volumes/GetStorageVolumeController.php @@ -8,8 +8,8 @@ class GetStorageVolumeController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getVolume; - + private GetVolume $getVolume; + public function __construct(GetVolume $getVolume) { $this->getVolume = $getVolume; diff --git a/src/classes/Controllers/Universe/GetEntitiesFromUniverseController.php b/src/classes/Controllers/Universe/GetEntitiesFromUniverseController.php index 4d3a6f14..f5d17bdb 100644 --- a/src/classes/Controllers/Universe/GetEntitiesFromUniverseController.php +++ b/src/classes/Controllers/Universe/GetEntitiesFromUniverseController.php @@ -6,14 +6,14 @@ class GetEntitiesFromUniverseController { - private $universe; - + private Universe $universe; + public function __construct(Universe $universe) { $this->universe = $universe; } - public function get(int $userId, string $entity = null) + public function get(int $userId, string $entity = null) :array { return $this->universe->getEntitiesUserHasAccesTo($userId, $entity); } diff --git a/src/classes/Controllers/User/AllowedProjects/GetUserAllowedProjectsController.php b/src/classes/Controllers/User/AllowedProjects/GetUserAllowedProjectsController.php index de598075..b174dedc 100644 --- a/src/classes/Controllers/User/AllowedProjects/GetUserAllowedProjectsController.php +++ b/src/classes/Controllers/User/AllowedProjects/GetUserAllowedProjectsController.php @@ -7,7 +7,7 @@ class GetUserAllowedProjectsController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $getUserAllowedProjects; + private GetUserAllowedProjects $getUserAllowedProjects; public function __construct(GetUserAllowedProjects $getUserAllowedProjects) { @@ -16,7 +16,7 @@ public function __construct(GetUserAllowedProjects $getUserAllowedProjects) /** * @Route("", name="Get a users allowed projects") */ - public function get(int $userId, int $targetUser) + public function get(int $userId, int $targetUser) :array { return $this->getUserAllowedProjects->get($userId, $targetUser); } diff --git a/src/classes/Controllers/User/AllowedProjects/GrantAccessController.php b/src/classes/Controllers/User/AllowedProjects/GrantAccessController.php index b90211ab..fb113edd 100644 --- a/src/classes/Controllers/User/AllowedProjects/GrantAccessController.php +++ b/src/classes/Controllers/User/AllowedProjects/GrantAccessController.php @@ -7,7 +7,7 @@ class GrantAccessController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $grantAccess; + private GrantAccess $grantAccess; public function __construct(GrantAccess $grantAccess) { @@ -16,7 +16,7 @@ public function __construct(GrantAccess $grantAccess) /** * @Route("", name="Grant user access to a hosts project") */ - public function grant(int $userId, int $targetUser, array $hosts, array $projects) + public function grant(int $userId, int $targetUser, array $hosts, array $projects) :array { $this->grantAccess->grant($userId, $targetUser, $hosts, $projects); return ["state"=>"success", "message"=>"Granted Access"]; diff --git a/src/classes/Controllers/User/AllowedProjects/GrantAccessToProjectController.php b/src/classes/Controllers/User/AllowedProjects/GrantAccessToProjectController.php index 8f61c8a5..c03df912 100644 --- a/src/classes/Controllers/User/AllowedProjects/GrantAccessToProjectController.php +++ b/src/classes/Controllers/User/AllowedProjects/GrantAccessToProjectController.php @@ -8,7 +8,7 @@ class GrantAccessToProjectController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $grantAccessToProject; + private GrantAccessToProject $grantAccessToProject; public function __construct(GrantAccessToProject $grantAccessToProject) { @@ -17,7 +17,7 @@ public function __construct(GrantAccessToProject $grantAccessToProject) /** * @Route("", name="Grant a user access to one hosts project") */ - public function grant(int $userId, array $targetUsers, Host $host, string $project) + public function grant(int $userId, array $targetUsers, Host $host, string $project) :array { $this->grantAccessToProject->grant($userId, $targetUsers, $host, $project); return ["state"=>"success", "message"=>"Granted Access"]; diff --git a/src/classes/Controllers/User/AllowedProjects/RevokeAccessController.php b/src/classes/Controllers/User/AllowedProjects/RevokeAccessController.php index e548f6c7..9d3e0945 100644 --- a/src/classes/Controllers/User/AllowedProjects/RevokeAccessController.php +++ b/src/classes/Controllers/User/AllowedProjects/RevokeAccessController.php @@ -7,7 +7,7 @@ class RevokeAccessController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $revokeAccess; + private RevokeAccess $revokeAccess; public function __construct(RevokeAccess $revokeAccess) { @@ -16,7 +16,7 @@ public function __construct(RevokeAccess $revokeAccess) /** * @Route("", name="Revoke a users access from a hosts project") */ - public function revoke(int $userId, int $targetUser, int $hostId, string $project) + public function revoke(int $userId, int $targetUser, int $hostId, string $project) :array { $this->revokeAccess->revoke($userId, $targetUser, $hostId, $project); return ["state"=>"success", "message"=>"Revoked Access"]; diff --git a/src/classes/Controllers/User/Dashboard/CreateDashboardController.php b/src/classes/Controllers/User/Dashboard/CreateDashboardController.php index 3a8d5c7a..4436c5fa 100644 --- a/src/classes/Controllers/User/Dashboard/CreateDashboardController.php +++ b/src/classes/Controllers/User/Dashboard/CreateDashboardController.php @@ -6,14 +6,14 @@ class CreateDashboardController { - private $insertUserDashboard; - + private InsertUserDashboard $insertUserDashboard; + public function __construct(InsertUserDashboard $insertUserDashboard) { $this->insertUserDashboard = $insertUserDashboard; } - public function create(int $userId, string $name) + public function create(int $userId, string $name) :array { $this->insertUserDashboard->insert($userId, $name); return ["state"=>"success", "message"=>"Created dashbaord"]; diff --git a/src/classes/Controllers/User/Dashboard/DeleteDashboardController.php b/src/classes/Controllers/User/Dashboard/DeleteDashboardController.php index 1c65a102..250bf4c4 100644 --- a/src/classes/Controllers/User/Dashboard/DeleteDashboardController.php +++ b/src/classes/Controllers/User/Dashboard/DeleteDashboardController.php @@ -6,14 +6,14 @@ class DeleteDashboardController { - private $deleteDashboard; + private DeleteDashboard $deleteDashboard; public function __construct(DeleteDashboard $deleteDashboard) { $this->deleteDashboard = $deleteDashboard; } - public function delete(int $userId, int $dashboardId) + public function delete(int $userId, int $dashboardId) :array { $this->deleteDashboard->delete($userId, $dashboardId); return ["state"=>"success", "message"=>"Deleted dashboard"]; diff --git a/src/classes/Controllers/User/Dashboard/GetDashboardController.php b/src/classes/Controllers/User/Dashboard/GetDashboardController.php index a80a149e..5fb12b42 100644 --- a/src/classes/Controllers/User/Dashboard/GetDashboardController.php +++ b/src/classes/Controllers/User/Dashboard/GetDashboardController.php @@ -6,14 +6,14 @@ class GetDashboardController { - private $getUserDashboard; - + private GetUserDashboard $getUserDashboard; + public function __construct(GetUserDashboard $getUserDashboard) { $this->getUserDashboard = $getUserDashboard; } - public function get(int $userId, int $dashboardId) + public function get(int $userId, int $dashboardId) :array { return $this->getUserDashboard->get($userId, $dashboardId); } diff --git a/src/classes/Controllers/User/Dashboard/Graphs/AddGraphController.php b/src/classes/Controllers/User/Dashboard/Graphs/AddGraphController.php index 33bb4a28..23a61f21 100644 --- a/src/classes/Controllers/User/Dashboard/Graphs/AddGraphController.php +++ b/src/classes/Controllers/User/Dashboard/Graphs/AddGraphController.php @@ -6,7 +6,7 @@ class AddGraphController { - private $addGraph; + private AddGraph $addGraph; public function __construct(AddGraph $addGraph) { @@ -22,7 +22,7 @@ public function add( int $metricId, string $filter, string $range - ) { + ) :array { $this->addGraph->add( $userId, $dashboardId, diff --git a/src/classes/Controllers/User/Dashboard/Graphs/DeleteGraphController.php b/src/classes/Controllers/User/Dashboard/Graphs/DeleteGraphController.php index e2907144..c4cc57a5 100644 --- a/src/classes/Controllers/User/Dashboard/Graphs/DeleteGraphController.php +++ b/src/classes/Controllers/User/Dashboard/Graphs/DeleteGraphController.php @@ -6,14 +6,14 @@ class DeleteGraphController { - private $deleteGraph; + private DeleteGraph $deleteGraph; public function __construct(DeleteGraph $deleteGraph) { $this->deleteGraph = $deleteGraph; } - public function delete(int $userId, int $graphId) + public function delete(int $userId, int $graphId) :array { $this->deleteGraph->delete($userId, $graphId); return ["state"=>"success", "message"=>"Delete Graph"]; diff --git a/src/classes/Controllers/User/DeleteUserController.php b/src/classes/Controllers/User/DeleteUserController.php index fd0c7077..a006d8ef 100644 --- a/src/classes/Controllers/User/DeleteUserController.php +++ b/src/classes/Controllers/User/DeleteUserController.php @@ -8,8 +8,8 @@ class DeleteUserController implements \dhope0000\LXDClient\Interfaces\RecordAction { - private $deleteUser; - private $container; + private DeleteUser $deleteUser; + private Container $container; public function __construct(DeleteUser $deleteUser, Container $container) { @@ -27,7 +27,7 @@ public function delete( int $removeApiKeys = 1, int $deleteAuditLogs = 0, int $deleteBackupSchedules = 0 - ) { + ) :array { $this->container->call(["dhope0000\LXDClient\Model\Database\Database", "beginTransaction"]); $this->deleteUser->delete( $userId, diff --git a/src/classes/Controllers/User/GetUserOverviewController.php b/src/classes/Controllers/User/GetUserOverviewController.php index ecdacb57..6857024e 100644 --- a/src/classes/Controllers/User/GetUserOverviewController.php +++ b/src/classes/Controllers/User/GetUserOverviewController.php @@ -7,9 +7,9 @@ class GetUserOverviewController { - private $getUserOverview; - private $validatePermissions; - + private GetUserOverview $getUserOverview; + private ValidatePermissions $validatePermissions; + public function __construct( GetUserOverview $getUserOverview, ValidatePermissions $validatePermissions @@ -18,7 +18,7 @@ public function __construct( $this->validatePermissions = $validatePermissions; } - public function get(int $userId, int $targetUser) + public function get(int $userId, int $targetUser) :array { $this->validatePermissions->isAdminOrThrow($userId); return $this->getUserOverview->get($userId, $targetUser); diff --git a/src/classes/Controllers/User/SetHostProjectController.php b/src/classes/Controllers/User/SetHostProjectController.php index 0ce57fc1..657e6266 100644 --- a/src/classes/Controllers/User/SetHostProjectController.php +++ b/src/classes/Controllers/User/SetHostProjectController.php @@ -6,14 +6,14 @@ class SetHostProjectController { - private $setUserProject; - + private SetUserProject $setUserProject; + public function __construct(SetUserProject $setUserProject) { $this->setUserProject = $setUserProject; } - public function set(int $userId, int $hostId, string $project) + public function set(int $userId, int $hostId, string $project) :array { $this->setUserProject->set($userId, $hostId, $project); return ["state"=>"success", "message"=>"Changed project to $project"]; diff --git a/src/classes/Controllers/User/ToggleAdminStatusController.php b/src/classes/Controllers/User/ToggleAdminStatusController.php index f5a06f1f..d5ea2006 100644 --- a/src/classes/Controllers/User/ToggleAdminStatusController.php +++ b/src/classes/Controllers/User/ToggleAdminStatusController.php @@ -7,9 +7,9 @@ class ToggleAdminStatusController { - private $toggleAdminStatus; - private $validatePermissions; - + private ToggleAdminStatus $toggleAdminStatus; + private ValidatePermissions $validatePermissions; + public function __construct( ToggleAdminStatus $toggleAdminStatus, ValidatePermissions $validatePermissions @@ -18,7 +18,7 @@ public function __construct( $this->validatePermissions = $validatePermissions; } - public function toggle(int $userId, int $targetUser, int $status) + public function toggle(int $userId, int $targetUser, int $status) :array { $this->validatePermissions->isAdminOrThrow($userId); $this->toggleAdminStatus->toggle($targetUser, $status); diff --git a/src/classes/Controllers/User/ToggleLoginStatusController.php b/src/classes/Controllers/User/ToggleLoginStatusController.php index 4c668107..ce6106f8 100644 --- a/src/classes/Controllers/User/ToggleLoginStatusController.php +++ b/src/classes/Controllers/User/ToggleLoginStatusController.php @@ -7,9 +7,9 @@ class ToggleLoginStatusController { - private $toggleLoginStatus; - private $validatePermissions; - + private ToggleLoginStatus $toggleLoginStatus; + private ValidatePermissions $validatePermissions; + public function __construct( ToggleLoginStatus $toggleLoginStatus, ValidatePermissions $validatePermissions @@ -18,7 +18,7 @@ public function __construct( $this->validatePermissions = $validatePermissions; } - public function toggle(int $userId, int $targetUser, int $status) + public function toggle(int $userId, int $targetUser, int $status) :array { $this->validatePermissions->isAdminOrThrow($userId); $this->toggleLoginStatus->toggle($targetUser, $status); diff --git a/src/classes/Controllers/User/Tokens/CreateTokenController.php b/src/classes/Controllers/User/Tokens/CreateTokenController.php index abb5bf32..d4ec8930 100644 --- a/src/classes/Controllers/User/Tokens/CreateTokenController.php +++ b/src/classes/Controllers/User/Tokens/CreateTokenController.php @@ -6,14 +6,14 @@ class CreateTokenController { - private $insertToken; - + private InsertToken $insertToken; + public function __construct(InsertToken $insertToken) { $this->insertToken = $insertToken; } - public function create(int $userId, string $token) + public function create(int $userId, string $token) :array { $this->insertToken->insert($userId, $token, 1); return ["state"=>"success", "message"=>"Create API permanent key"]; diff --git a/src/classes/Controllers/User/Tokens/DeleteTokenController.php b/src/classes/Controllers/User/Tokens/DeleteTokenController.php index b8bae6fd..9d6c6f08 100644 --- a/src/classes/Controllers/User/Tokens/DeleteTokenController.php +++ b/src/classes/Controllers/User/Tokens/DeleteTokenController.php @@ -6,14 +6,14 @@ class DeleteTokenController { - private $deleteToken; + private DeleteToken $deleteToken; public function __construct(DeleteToken $deleteToken) { $this->deleteToken = $deleteToken; } - public function delete(int $userId, int $tokenId) + public function delete(int $userId, int $tokenId) :array { $this->deleteToken->delete($userId, $tokenId); return ["state"=>"success", "message"=>"Deleted token"]; diff --git a/src/classes/Exceptions/Users/CantFindUserException.php b/src/classes/Exceptions/Users/CantFindUserException.php index 491035e3..5aa905c2 100644 --- a/src/classes/Exceptions/Users/CantFindUserException.php +++ b/src/classes/Exceptions/Users/CantFindUserException.php @@ -4,7 +4,7 @@ class CantFindUserException extends \Exception { - public function __construct($username) + public function __construct(string $username) { parent::__construct("Cant find user account for $username"); } diff --git a/src/classes/Exceptions/Users/DisabledUserAttemptedLogin.php b/src/classes/Exceptions/Users/DisabledUserAttemptedLogin.php index e3ae708b..b8fc74a0 100644 --- a/src/classes/Exceptions/Users/DisabledUserAttemptedLogin.php +++ b/src/classes/Exceptions/Users/DisabledUserAttemptedLogin.php @@ -5,7 +5,7 @@ class DisabledUserAttemptedLogin extends \Exception { /** @phpstan-ignore-next-line */ - public function __construct($username) + public function __construct(string $username) { parent::__construct("Cant login right now - contact admin"); } diff --git a/src/classes/Exceptions/Users/PasswordIncorrectException.php b/src/classes/Exceptions/Users/PasswordIncorrectException.php index e0872b2b..0cca7e16 100644 --- a/src/classes/Exceptions/Users/PasswordIncorrectException.php +++ b/src/classes/Exceptions/Users/PasswordIncorrectException.php @@ -4,7 +4,7 @@ class PasswordIncorrectException extends \Exception { - public function __construct($username) + public function __construct(string $username) { parent::__construct("Password incorrect for $username"); } diff --git a/src/classes/Model/Analytics/FetchLatestData.php b/src/classes/Model/Analytics/FetchLatestData.php index 41711f96..5a1d2dfd 100644 --- a/src/classes/Model/Analytics/FetchLatestData.php +++ b/src/classes/Model/Analytics/FetchLatestData.php @@ -6,14 +6,14 @@ class FetchLatestData { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function lastHour() + public function lastHour() :array { $mod = isset($_ENV["DB_SQLITE"]) && !empty($_ENV["DB_SQLITE"]) ? "datetime('now', '-3600 seconds')" : "DATE_SUB(NOW(), INTERVAL 1 HOUR)"; $sql = "SELECT @@ -33,7 +33,7 @@ public function lastHour() return $do->fetchAll(\PDO::FETCH_ASSOC); } - public function lastEntry() + public function lastEntry() :array { $sql = "SELECT `FA_Date_Created` as `dateTime`, @@ -52,7 +52,7 @@ public function lastEntry() return $do->fetch(\PDO::FETCH_ASSOC); } - public function fetchAll() + public function fetchAll() :array { $sql = "SELECT `FA_Date_Created` as `dateTime`, diff --git a/src/classes/Model/Backups/DeleteBackup.php b/src/classes/Model/Backups/DeleteBackup.php index 382260d1..888e90ed 100644 --- a/src/classes/Model/Backups/DeleteBackup.php +++ b/src/classes/Model/Backups/DeleteBackup.php @@ -6,14 +6,14 @@ class DeleteBackup { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteBefore(\DateTimeInterface $before) + public function deleteBefore(\DateTimeInterface $before) :bool { $sql = "DELETE FROM `Container_Backups` @@ -27,7 +27,7 @@ public function deleteBefore(\DateTimeInterface $before) return $do->rowCount() ? true : false; } - public function setDeleted(int $backupId) + public function setDeleted(int $backupId) :bool { $sql = "UPDATE `Container_Backups` @@ -43,7 +43,7 @@ public function setDeleted(int $backupId) return $do->rowCount() ? true : false; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `Container_Backups` diff --git a/src/classes/Model/Backups/FetchBackup.php b/src/classes/Model/Backups/FetchBackup.php index 5f90aa4d..61957c9a 100644 --- a/src/classes/Model/Backups/FetchBackup.php +++ b/src/classes/Model/Backups/FetchBackup.php @@ -6,7 +6,7 @@ class FetchBackup { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Backups/FetchBackups.php b/src/classes/Model/Backups/FetchBackups.php index 1972fda0..cc262174 100644 --- a/src/classes/Model/Backups/FetchBackups.php +++ b/src/classes/Model/Backups/FetchBackups.php @@ -6,7 +6,7 @@ class FetchBackups { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Client/LxdClient.php b/src/classes/Model/Client/LxdClient.php index 69544b3c..68b4e102 100755 --- a/src/classes/Model/Client/LxdClient.php +++ b/src/classes/Model/Client/LxdClient.php @@ -11,11 +11,11 @@ class LxdClient { - private $routeApi; - private $getUserProject; - private $getDetails; - - private $clientBag = []; + private RouteApi $routeApi; + private GetUserProject $getUserProject; + private GetDetails $getDetails; + + private array $clientBag = []; public function __construct( RouteApi $routeApi, @@ -27,7 +27,7 @@ public function __construct( $this->getDetails = $getDetails; } - public function getClientWithHost(Host $host, $checkCache = true, $setProject = true) + public function getClientWithHost(Host $host, bool $checkCache = true, bool $setProject = true) :Client { if ($checkCache && isset($this->clientBag[$host->getUrl()])) { return $this->clientBag[$host->getUrl()]; @@ -55,12 +55,12 @@ public function getClientWithHost(Host $host, $checkCache = true, $setProject = return $client; } - private function createFullcertPath(string $certName) + private function createFullcertPath(string $certName) :string { return $_ENV["LXD_CERTS_DIR"] . $certName; } - public function createConfigArray($certLocation, $socketPath) + public function createConfigArray(string $certLocation, ?string $socketPath) :array { $certPath = realpath($certLocation); @@ -85,7 +85,7 @@ public function createConfigArray($certLocation, $socketPath) return $config; } - public function createNewClient($urlAndPort, $config) + public function createNewClient(string $urlAndPort, array $config) :Client { $s = $urlAndPort; if (isset($config["curl"]) && isset($config["curl"][CURLOPT_UNIX_SOCKET_PATH])) { diff --git a/src/classes/Model/CloudConfig/CreateConfig.php b/src/classes/Model/CloudConfig/CreateConfig.php index e7c2a63c..57ae549a 100644 --- a/src/classes/Model/CloudConfig/CreateConfig.php +++ b/src/classes/Model/CloudConfig/CreateConfig.php @@ -5,14 +5,14 @@ class CreateConfig { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function create(string $name, string $namespace, $description) + public function create(string $name, string $namespace, string $description) :bool { $sql = "INSERT INTO `Cloud_Config` ( diff --git a/src/classes/Model/CloudConfig/Data/Update.php b/src/classes/Model/CloudConfig/Data/Update.php index 37436253..9171c1c5 100644 --- a/src/classes/Model/CloudConfig/Data/Update.php +++ b/src/classes/Model/CloudConfig/Data/Update.php @@ -5,7 +5,7 @@ class Update { - private $database; + private \PDO $database; public function __construct(Database $database) { @@ -17,7 +17,7 @@ public function insert( string $codeJson, string $imageJson, string $envVariablesJson - ) { + ) :bool { $sql = "INSERT INTO `Cloud_Config_Data` ( `CCD_Cloud_Config_ID`, diff --git a/src/classes/Model/CloudConfig/DeleteCloudConfig.php b/src/classes/Model/CloudConfig/DeleteCloudConfig.php index b1375ed4..542c0ee8 100644 --- a/src/classes/Model/CloudConfig/DeleteCloudConfig.php +++ b/src/classes/Model/CloudConfig/DeleteCloudConfig.php @@ -5,14 +5,14 @@ class DeleteCloudConfig { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $cloudConfigId) + public function delete(int $cloudConfigId) :bool { $sql = "DELETE FROM `Cloud_Config` diff --git a/src/classes/Model/CloudConfig/GetConfig.php b/src/classes/Model/CloudConfig/GetConfig.php index b5bb2bbc..2b189847 100644 --- a/src/classes/Model/CloudConfig/GetConfig.php +++ b/src/classes/Model/CloudConfig/GetConfig.php @@ -5,7 +5,7 @@ class GetConfig { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/CloudConfig/GetConfigs.php b/src/classes/Model/CloudConfig/GetConfigs.php index 1f812c45..1af5962e 100644 --- a/src/classes/Model/CloudConfig/GetConfigs.php +++ b/src/classes/Model/CloudConfig/GetConfigs.php @@ -5,7 +5,7 @@ class GetConfigs { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/CloudConfig/Namespaces/GetCloudConfigs.php b/src/classes/Model/CloudConfig/Namespaces/GetCloudConfigs.php index 7fdcde58..fd62c236 100644 --- a/src/classes/Model/CloudConfig/Namespaces/GetCloudConfigs.php +++ b/src/classes/Model/CloudConfig/Namespaces/GetCloudConfigs.php @@ -6,14 +6,14 @@ class GetCloudConfigs { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function haveCloudConfigInNamespace(string $name, string $namespace) + public function haveCloudConfigInNamespace(string $name, string $namespace) :bool { $sql = "SELECT 1 diff --git a/src/classes/Model/CloudConfig/Search/SearchCloudConfig.php b/src/classes/Model/CloudConfig/Search/SearchCloudConfig.php index 918e7adb..4f0dece2 100644 --- a/src/classes/Model/CloudConfig/Search/SearchCloudConfig.php +++ b/src/classes/Model/CloudConfig/Search/SearchCloudConfig.php @@ -6,7 +6,7 @@ class SearchCloudConfig { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Database/Database.php b/src/classes/Model/Database/Database.php index 56b7f93e..567161b4 100755 --- a/src/classes/Model/Database/Database.php +++ b/src/classes/Model/Database/Database.php @@ -4,7 +4,7 @@ class Database { - public $dbObject; + public \PDO $dbObject; public function __construct() { @@ -17,20 +17,24 @@ public function __construct() $this->dbObject->exec("SET time_zone='$tz';"); } + if ($this->dbObject == false) { + throw new \Exception("Couldn't connect to database", 1); + } + $this->dbObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } - public function beginTransaction() + public function beginTransaction() :void { $this->dbObject->beginTransaction(); } - public function commitTransaction() + public function commitTransaction() :void { $this->dbObject->commit(); } - public function rollbackTransaction() + public function rollbackTransaction() :void { $this->dbObject->rollback(); } diff --git a/src/classes/Model/Deployments/CloudConfig/AddCloudConfig.php b/src/classes/Model/Deployments/CloudConfig/AddCloudConfig.php index 4cd748b5..1ad877ee 100644 --- a/src/classes/Model/Deployments/CloudConfig/AddCloudConfig.php +++ b/src/classes/Model/Deployments/CloudConfig/AddCloudConfig.php @@ -6,14 +6,14 @@ class AddCloudConfig { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function add(int $deploymentId, int $cloudConfigRevId) + public function add(int $deploymentId, int $cloudConfigRevId) :bool { $sql = "INSERT INTO `Deployment_Cloud_Config` ( diff --git a/src/classes/Model/Deployments/CloudConfig/FetchCloudConfigs.php b/src/classes/Model/Deployments/CloudConfig/FetchCloudConfigs.php index e9b880f9..8aa3b77c 100644 --- a/src/classes/Model/Deployments/CloudConfig/FetchCloudConfigs.php +++ b/src/classes/Model/Deployments/CloudConfig/FetchCloudConfigs.php @@ -6,7 +6,7 @@ class FetchCloudConfigs { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/CloudConfig/GetCloudConfigs.php b/src/classes/Model/Deployments/CloudConfig/GetCloudConfigs.php index e0d58b27..36cd90d8 100644 --- a/src/classes/Model/Deployments/CloudConfig/GetCloudConfigs.php +++ b/src/classes/Model/Deployments/CloudConfig/GetCloudConfigs.php @@ -6,7 +6,7 @@ class GetCloudConfigs { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/Containers/DeleteDeploymentInstances.php b/src/classes/Model/Deployments/Containers/DeleteDeploymentInstances.php index bebc3b6e..6ede7412 100644 --- a/src/classes/Model/Deployments/Containers/DeleteDeploymentInstances.php +++ b/src/classes/Model/Deployments/Containers/DeleteDeploymentInstances.php @@ -6,14 +6,14 @@ class DeleteDeploymentInstances { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `Deployment_Containers` diff --git a/src/classes/Model/Deployments/Containers/GetDeployedContainers.php b/src/classes/Model/Deployments/Containers/GetDeployedContainers.php index 9c92ab62..3e15f41e 100644 --- a/src/classes/Model/Deployments/Containers/GetDeployedContainers.php +++ b/src/classes/Model/Deployments/Containers/GetDeployedContainers.php @@ -6,7 +6,7 @@ class GetDeployedContainers { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/Containers/InsertDeploymentContainer.php b/src/classes/Model/Deployments/Containers/InsertDeploymentContainer.php index 5990ba0f..f3fd60ad 100644 --- a/src/classes/Model/Deployments/Containers/InsertDeploymentContainer.php +++ b/src/classes/Model/Deployments/Containers/InsertDeploymentContainer.php @@ -6,14 +6,14 @@ class InsertDeploymentContainer { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $deploymentId, int $hostId, string $name) + public function insert(int $deploymentId, int $hostId, string $name) :bool { $sql = "INSERT INTO `Deployment_Containers` ( `DC_Deployment_ID`, diff --git a/src/classes/Model/Deployments/Containers/UpdatePhoneHomeTime.php b/src/classes/Model/Deployments/Containers/UpdatePhoneHomeTime.php index 89092679..6f199aa8 100644 --- a/src/classes/Model/Deployments/Containers/UpdatePhoneHomeTime.php +++ b/src/classes/Model/Deployments/Containers/UpdatePhoneHomeTime.php @@ -6,14 +6,14 @@ class UpdatePhoneHomeTime { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function update(int $deploymentId, string $name) + public function update(int $deploymentId, string $name) :bool { $sql = "UPDATE `Deployment_Containers` diff --git a/src/classes/Model/Deployments/Containers/UpdateStartTimes.php b/src/classes/Model/Deployments/Containers/UpdateStartTimes.php index d8811b33..58682a4e 100644 --- a/src/classes/Model/Deployments/Containers/UpdateStartTimes.php +++ b/src/classes/Model/Deployments/Containers/UpdateStartTimes.php @@ -6,14 +6,14 @@ class UpdateStartTimes { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function updateFirstStart(int $deploymentId, int $hostId, string $name) + public function updateFirstStart(int $deploymentId, int $hostId, string $name) :bool { $sql = "UPDATE `Deployment_Containers` @@ -37,7 +37,7 @@ public function updateFirstStart(int $deploymentId, int $hostId, string $name) return $do->rowCount() ? true : false; } - public function updateLastStart(int $deploymentId, int $hostId, string $name) + public function updateLastStart(int $deploymentId, int $hostId, string $name) :bool { $sql = "UPDATE `Deployment_Containers` diff --git a/src/classes/Model/Deployments/FetchDeployments.php b/src/classes/Model/Deployments/FetchDeployments.php index 49d55b71..3458867c 100644 --- a/src/classes/Model/Deployments/FetchDeployments.php +++ b/src/classes/Model/Deployments/FetchDeployments.php @@ -6,7 +6,7 @@ class FetchDeployments { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/InsertDeployment.php b/src/classes/Model/Deployments/InsertDeployment.php index 272da340..8a4959ef 100644 --- a/src/classes/Model/Deployments/InsertDeployment.php +++ b/src/classes/Model/Deployments/InsertDeployment.php @@ -6,14 +6,14 @@ class InsertDeployment { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(string $name) + public function insert(string $name) :bool { $sql = "INSERT INTO `Deployments` ( diff --git a/src/classes/Model/Deployments/Projects/DeleteDeploymentProject.php b/src/classes/Model/Deployments/Projects/DeleteDeploymentProject.php index 09288b89..8b22edb2 100644 --- a/src/classes/Model/Deployments/Projects/DeleteDeploymentProject.php +++ b/src/classes/Model/Deployments/Projects/DeleteDeploymentProject.php @@ -6,7 +6,7 @@ class DeleteDeploymentProject { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/Projects/FetchDeploymentProjects.php b/src/classes/Model/Deployments/Projects/FetchDeploymentProjects.php index 07e651ad..b1dd8411 100644 --- a/src/classes/Model/Deployments/Projects/FetchDeploymentProjects.php +++ b/src/classes/Model/Deployments/Projects/FetchDeploymentProjects.php @@ -6,7 +6,7 @@ class FetchDeploymentProjects { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/Projects/FetchDeploymentProjectsUsers.php b/src/classes/Model/Deployments/Projects/FetchDeploymentProjectsUsers.php index ed265d57..43b744bb 100644 --- a/src/classes/Model/Deployments/Projects/FetchDeploymentProjectsUsers.php +++ b/src/classes/Model/Deployments/Projects/FetchDeploymentProjectsUsers.php @@ -6,7 +6,7 @@ class FetchDeploymentProjectsUsers { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/Projects/InsertDeploymentProject.php b/src/classes/Model/Deployments/Projects/InsertDeploymentProject.php index 3f5552ad..61f85967 100644 --- a/src/classes/Model/Deployments/Projects/InsertDeploymentProject.php +++ b/src/classes/Model/Deployments/Projects/InsertDeploymentProject.php @@ -6,7 +6,7 @@ class InsertDeploymentProject { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Deployments/RemoveDeployment.php b/src/classes/Model/Deployments/RemoveDeployment.php index 1bdcd830..7c9e3a2d 100644 --- a/src/classes/Model/Deployments/RemoveDeployment.php +++ b/src/classes/Model/Deployments/RemoveDeployment.php @@ -6,14 +6,14 @@ class RemoveDeployment { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $deploymentId) + public function delete(int $deploymentId) :bool { $sql = "DELETE FROM `Deployments` diff --git a/src/classes/Model/Hosts/AddHost.php b/src/classes/Model/Hosts/AddHost.php index 61e49eaa..ae896353 100644 --- a/src/classes/Model/Hosts/AddHost.php +++ b/src/classes/Model/Hosts/AddHost.php @@ -6,15 +6,21 @@ class AddHost { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function addHost($urlAndPort, $keyPath, $certPath, $combiendPath, $alias = null, $socketPath = "") - { + public function addHost( + string $urlAndPort, + string $keyPath, + string $certPath, + string $combiendPath, + string $alias = null, + ?string $socketPath = "" + ) :bool { $sql = "INSERT INTO `Hosts` ( `Host_Url_And_Port`, diff --git a/src/classes/Model/Hosts/Backups/Instances/FetchInstanceBackups.php b/src/classes/Model/Hosts/Backups/Instances/FetchInstanceBackups.php index 11b1ad12..7a88dcac 100644 --- a/src/classes/Model/Hosts/Backups/Instances/FetchInstanceBackups.php +++ b/src/classes/Model/Hosts/Backups/Instances/FetchInstanceBackups.php @@ -6,7 +6,7 @@ class FetchInstanceBackups { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Hosts/Backups/Instances/InsertInstanceBackup.php b/src/classes/Model/Hosts/Backups/Instances/InsertInstanceBackup.php index 2b94b30b..65b561a1 100644 --- a/src/classes/Model/Hosts/Backups/Instances/InsertInstanceBackup.php +++ b/src/classes/Model/Hosts/Backups/Instances/InsertInstanceBackup.php @@ -6,8 +6,8 @@ class InsertInstanceBackup { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; @@ -23,7 +23,7 @@ public function insert( int $filesize, int $failed = 0, string $failedReason = "" - ) { + ) :bool { $sql = "INSERT INTO `Container_Backups` ( `CB_Backup_Date_Created`, diff --git a/src/classes/Model/Hosts/Backups/Instances/Schedules/DeleteBackupSchedules.php b/src/classes/Model/Hosts/Backups/Instances/Schedules/DeleteBackupSchedules.php index 453d0327..7cd94fa6 100644 --- a/src/classes/Model/Hosts/Backups/Instances/Schedules/DeleteBackupSchedules.php +++ b/src/classes/Model/Hosts/Backups/Instances/Schedules/DeleteBackupSchedules.php @@ -6,14 +6,14 @@ class DeleteBackupSchedules { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteforHost(int $hostId) + public function deleteforHost(int $hostId) :bool { $sql = "DELETE FROM `Instance_Backup_Schedule` @@ -27,7 +27,7 @@ public function deleteforHost(int $hostId) return $do->rowCount() ? true : false; } - public function deleteforUser(int $userId) + public function deleteforUser(int $userId) :bool { $sql = "DELETE FROM `Instance_Backup_Schedule` diff --git a/src/classes/Model/Hosts/Backups/Instances/Schedules/FetchBackupSchedules.php b/src/classes/Model/Hosts/Backups/Instances/Schedules/FetchBackupSchedules.php index 8311013c..3e4d7c12 100644 --- a/src/classes/Model/Hosts/Backups/Instances/Schedules/FetchBackupSchedules.php +++ b/src/classes/Model/Hosts/Backups/Instances/Schedules/FetchBackupSchedules.php @@ -6,7 +6,7 @@ class FetchBackupSchedules { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Hosts/Backups/Instances/Schedules/InsertBackupSchedule.php b/src/classes/Model/Hosts/Backups/Instances/Schedules/InsertBackupSchedule.php index 8eefe48e..2dd59b1c 100644 --- a/src/classes/Model/Hosts/Backups/Instances/Schedules/InsertBackupSchedule.php +++ b/src/classes/Model/Hosts/Backups/Instances/Schedules/InsertBackupSchedule.php @@ -6,8 +6,8 @@ class InsertBackupSchedule { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; @@ -21,7 +21,7 @@ public function insert( string $schedule, int $strategyId, int $retention - ) { + ) :bool { $sql = "INSERT INTO `Instance_Backup_Schedule` ( `IBS_User_ID`, diff --git a/src/classes/Model/Hosts/Backups/Instances/Schedules/UpdateBackupSchedules.php b/src/classes/Model/Hosts/Backups/Instances/Schedules/UpdateBackupSchedules.php index e19781a0..773cf42e 100644 --- a/src/classes/Model/Hosts/Backups/Instances/Schedules/UpdateBackupSchedules.php +++ b/src/classes/Model/Hosts/Backups/Instances/Schedules/UpdateBackupSchedules.php @@ -6,8 +6,8 @@ class UpdateBackupSchedules { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; @@ -18,7 +18,7 @@ public function disableActiveScheds( int $hostId, string $instance, string $project - ) { + ) :bool { $sql = "UPDATE `Instance_Backup_Schedule` SET `IBS_Disabled` = 1, diff --git a/src/classes/Model/Hosts/Backups/Strategies/FetchStrategies.php b/src/classes/Model/Hosts/Backups/Strategies/FetchStrategies.php index bc5dfefc..2277a219 100644 --- a/src/classes/Model/Hosts/Backups/Strategies/FetchStrategies.php +++ b/src/classes/Model/Hosts/Backups/Strategies/FetchStrategies.php @@ -6,7 +6,7 @@ class FetchStrategies { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Hosts/ChangeStatus.php b/src/classes/Model/Hosts/ChangeStatus.php index 60b4a7db..8053692c 100644 --- a/src/classes/Model/Hosts/ChangeStatus.php +++ b/src/classes/Model/Hosts/ChangeStatus.php @@ -13,7 +13,7 @@ public function __construct(Database $database) $this->db = $database->dbObject; } - public function setOnline($hostId) + public function setOnline(int $hostId) :bool { $sql = "UPDATE `Hosts` SET `Host_Online` = 1 WHERE `Host_ID` = :hostId"; $do = $this->db->prepare($sql); @@ -23,7 +23,7 @@ public function setOnline($hostId) return $do->rowCount() ? true : false; } - public function setOffline($hostId) + public function setOffline(int $hostId) :bool { $sql = "UPDATE `Hosts` SET `Host_Online` = 0 WHERE `Host_ID` = :hostId"; $do = $this->db->prepare($sql); diff --git a/src/classes/Model/Hosts/DeleteHost.php b/src/classes/Model/Hosts/DeleteHost.php index dfe4d92b..23fc7bd9 100644 --- a/src/classes/Model/Hosts/DeleteHost.php +++ b/src/classes/Model/Hosts/DeleteHost.php @@ -5,14 +5,14 @@ class DeleteHost { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $hostId) + public function delete(int $hostId) :bool { $sql = "DELETE FROM `Hosts` diff --git a/src/classes/Model/Hosts/GetDetails.php b/src/classes/Model/Hosts/GetDetails.php index 82275fc1..02d0a95a 100644 --- a/src/classes/Model/Hosts/GetDetails.php +++ b/src/classes/Model/Hosts/GetDetails.php @@ -8,7 +8,7 @@ class GetDetails { - private $database; + private \PDO $database; private $container; public function __construct(Database $database, Container $container) @@ -48,7 +48,7 @@ public function fetchAlias(int $hostId) return $do->fetchColumn(); } - public function fetchHost($hostId) + public function fetchHost(int $hostId) { $sql = "SELECT `Host_ID` as `id`, @@ -58,7 +58,8 @@ public function fetchHost($hostId) `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` WHERE @@ -73,7 +74,7 @@ public function fetchHost($hostId) return $do->fetchObject("dhope0000\LXDClient\Objects\Host", [$this->container->get("dhope0000\LXDClient\Model\Client\LxdClient")]); } - public function fetchHostByUrl($hostUrl) + public function fetchHostByUrl(string $hostUrl) { $sql = "SELECT `Host_ID` as `id`, @@ -83,7 +84,8 @@ public function fetchHostByUrl($hostUrl) `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` WHERE @@ -97,7 +99,7 @@ public function fetchHostByUrl($hostUrl) return $do->fetchObject("dhope0000\LXDClient\Objects\Host", [$this->container->get("dhope0000\LXDClient\Model\Client\LxdClient")]); } - public function getCertificate($hostId) + public function getCertificate(int $hostId) { $sql = "SELECT `Host_Cert_Path` @@ -115,7 +117,7 @@ public function getCertificate($hostId) return $do->fetchColumn(); } - public function getSocketPath($hostId) + public function getSocketPath(int $hostId) { $sql = "SELECT `Host_Socket_Path` diff --git a/src/classes/Model/Hosts/HostList.php b/src/classes/Model/Hosts/HostList.php index a2d37f80..5d975f86 100755 --- a/src/classes/Model/Hosts/HostList.php +++ b/src/classes/Model/Hosts/HostList.php @@ -7,9 +7,9 @@ class HostList { - private $database; + private \PDO $database; private $container; - + public function __construct(Database $database, Container $container) { $this->database = $database->dbObject; @@ -27,7 +27,8 @@ public function getHostCollection(array $hostIds) `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` WHERE @@ -71,7 +72,8 @@ public function getOnlineHostsWithDetails() `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` WHERE @@ -97,8 +99,9 @@ public function fetchHostsNotInList(array $hostIds) `Host_Cert_Only_File` as `certFilePath`, `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, - `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + '`Host_Online`' as `hostOnline`, + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` WHERE @@ -121,7 +124,8 @@ public function fetchAllHosts() `Host_Key_File` as `keyFilePath`, COALESCE(`Host_Alias`, `Host_Url_And_Port`) as `alias`, `Host_Online` as `hostOnline`, - `Host_Support_Load_Averages` as `supportsLoadAvgs` + `Host_Support_Load_Averages` as `supportsLoadAvgs`, + `Host_Socket_Path` as `socketPath` FROM `Hosts` ORDER BY diff --git a/src/classes/Model/Hosts/Settings/Alias/HaveAlias.php b/src/classes/Model/Hosts/Settings/Alias/HaveAlias.php index fb2823fc..a6edd53e 100644 --- a/src/classes/Model/Hosts/Settings/Alias/HaveAlias.php +++ b/src/classes/Model/Hosts/Settings/Alias/HaveAlias.php @@ -6,14 +6,14 @@ class HaveAlias { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function have(int $hostId, string $alias) + public function have(int $hostId, string $alias) :bool { $sql = "SELECT 1 diff --git a/src/classes/Model/Hosts/Settings/SetHostSettings.php b/src/classes/Model/Hosts/Settings/SetHostSettings.php index dc0316cb..e4d6510e 100644 --- a/src/classes/Model/Hosts/Settings/SetHostSettings.php +++ b/src/classes/Model/Hosts/Settings/SetHostSettings.php @@ -6,14 +6,14 @@ class SetHostSettings { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function set(int $hostId, string $alias, int $supportsLoadAverages) + public function set(int $hostId, string $alias, int $supportsLoadAverages) :bool { $sql = "UPDATE `Hosts` diff --git a/src/classes/Model/Hosts/UpdateHost.php b/src/classes/Model/Hosts/UpdateHost.php index 54f5a8ed..0a8a8426 100644 --- a/src/classes/Model/Hosts/UpdateHost.php +++ b/src/classes/Model/Hosts/UpdateHost.php @@ -5,14 +5,14 @@ class UpdateHost { - private $database; + private \PDO $database; public function __construct(Database $database) { $this->database = $database->dbObject; } - public function updateCertificateDetails(int $hostId, string $keyPath, string $certPath, string $combinedPath) + public function updateCertificateDetails(int $hostId, string $keyPath, string $certPath, string $combinedPath) :bool { $sql = "UPDATE `Hosts` SET `Host_Key_File` = :keyPath, diff --git a/src/classes/Model/InstanceSettings/GetSetting.php b/src/classes/Model/InstanceSettings/GetSetting.php index 2cbd7df2..adbbf1b3 100644 --- a/src/classes/Model/InstanceSettings/GetSetting.php +++ b/src/classes/Model/InstanceSettings/GetSetting.php @@ -6,7 +6,7 @@ class GetSetting { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/InstanceSettings/GetSettings.php b/src/classes/Model/InstanceSettings/GetSettings.php index d6707b78..d9c0925e 100644 --- a/src/classes/Model/InstanceSettings/GetSettings.php +++ b/src/classes/Model/InstanceSettings/GetSettings.php @@ -6,7 +6,7 @@ class GetSettings { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/InstanceSettings/InsertSetting.php b/src/classes/Model/InstanceSettings/InsertSetting.php index e6765c7e..a1928826 100644 --- a/src/classes/Model/InstanceSettings/InsertSetting.php +++ b/src/classes/Model/InstanceSettings/InsertSetting.php @@ -6,14 +6,14 @@ class InsertSetting { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $settingId, $value) + public function insert(int $settingId, string $value) :bool { $sql = "INSERT INTO `Instance_Settings_Values` diff --git a/src/classes/Model/InstanceSettings/RecordActions/DeleteRecordedActions.php b/src/classes/Model/InstanceSettings/RecordActions/DeleteRecordedActions.php index 19d561d3..1d61bf9f 100644 --- a/src/classes/Model/InstanceSettings/RecordActions/DeleteRecordedActions.php +++ b/src/classes/Model/InstanceSettings/RecordActions/DeleteRecordedActions.php @@ -6,14 +6,14 @@ class DeleteRecordedActions { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteForUser(int $userId) + public function deleteForUser(int $userId) :bool { $sql = "DELETE FROM `Recorded_Actions` WHERE diff --git a/src/classes/Model/InstanceSettings/RecordActions/FetchRecordedActions.php b/src/classes/Model/InstanceSettings/RecordActions/FetchRecordedActions.php index 5f8943e4..b8f03f6c 100644 --- a/src/classes/Model/InstanceSettings/RecordActions/FetchRecordedActions.php +++ b/src/classes/Model/InstanceSettings/RecordActions/FetchRecordedActions.php @@ -6,7 +6,7 @@ class FetchRecordedActions { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/InstanceSettings/RecordActions/InsertActionLog.php b/src/classes/Model/InstanceSettings/RecordActions/InsertActionLog.php index 1041321c..9e7e9593 100644 --- a/src/classes/Model/InstanceSettings/RecordActions/InsertActionLog.php +++ b/src/classes/Model/InstanceSettings/RecordActions/InsertActionLog.php @@ -6,14 +6,14 @@ class InsertActionLog { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $userId, string $controller, string $params) + public function insert(int $userId, string $controller, string $params) :bool { $sql = "INSERT INTO `Recorded_Actions` ( diff --git a/src/classes/Model/Instances/InstanceTypes/DeleteInstanceType.php b/src/classes/Model/Instances/InstanceTypes/DeleteInstanceType.php index 037babd1..a537f2af 100644 --- a/src/classes/Model/Instances/InstanceTypes/DeleteInstanceType.php +++ b/src/classes/Model/Instances/InstanceTypes/DeleteInstanceType.php @@ -6,20 +6,20 @@ class DeleteInstanceType { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $typeId) + public function delete(int $typeId) :bool { $sql = "DELETE FROM `Instance_Types` WHERE `IT_ID` = :typeId"; $do = $this->database->prepare($sql); $do->execute([ ":typeId"=>$typeId ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Instances/InstanceTypes/DeleteTypes.php b/src/classes/Model/Instances/InstanceTypes/DeleteTypes.php index bf797434..adeeb10e 100644 --- a/src/classes/Model/Instances/InstanceTypes/DeleteTypes.php +++ b/src/classes/Model/Instances/InstanceTypes/DeleteTypes.php @@ -6,20 +6,20 @@ class DeleteTypes { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteAllForProvider(int $providerId) + public function deleteAllForProvider(int $providerId) :bool { $sql = "DELETE FROM `Instance_Types` WHERE `IT_Provider_ID` = :providerId"; $do = $this->database->prepare($sql); $do->execute([ ":providerId"=>$providerId ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Instances/InstanceTypes/FetchInstanceType.php b/src/classes/Model/Instances/InstanceTypes/FetchInstanceType.php index 3896e5eb..d3a7ea33 100644 --- a/src/classes/Model/Instances/InstanceTypes/FetchInstanceType.php +++ b/src/classes/Model/Instances/InstanceTypes/FetchInstanceType.php @@ -6,14 +6,14 @@ class FetchInstanceType { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function fetchByName($name) + public function fetchByName(string $name) { $sql = "SELECT `ITP_ID` as `providerId`, diff --git a/src/classes/Model/Instances/InstanceTypes/FetchInstanceTypes.php b/src/classes/Model/Instances/InstanceTypes/FetchInstanceTypes.php index 82fe94c5..d25a4a16 100644 --- a/src/classes/Model/Instances/InstanceTypes/FetchInstanceTypes.php +++ b/src/classes/Model/Instances/InstanceTypes/FetchInstanceTypes.php @@ -6,7 +6,7 @@ class FetchInstanceTypes { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Instances/InstanceTypes/InsertInstanceType.php b/src/classes/Model/Instances/InstanceTypes/InsertInstanceType.php index 1116a744..ed44dd8e 100644 --- a/src/classes/Model/Instances/InstanceTypes/InsertInstanceType.php +++ b/src/classes/Model/Instances/InstanceTypes/InsertInstanceType.php @@ -6,14 +6,14 @@ class InsertInstanceType { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $providerId, string $name, float $cpu, float $mem) + public function insert(int $providerId, string $name, float $cpu, float $mem) :bool { $sql = "INSERT INTO `Instance_Types`( `IT_Provider_ID`, @@ -33,6 +33,6 @@ public function insert(int $providerId, string $name, float $cpu, float $mem) ":cpu"=>$cpu, ":mem"=>$mem ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Instances/InstanceTypes/Providers/DeleteProvider.php b/src/classes/Model/Instances/InstanceTypes/Providers/DeleteProvider.php index b7d9060c..ae26c0c1 100644 --- a/src/classes/Model/Instances/InstanceTypes/Providers/DeleteProvider.php +++ b/src/classes/Model/Instances/InstanceTypes/Providers/DeleteProvider.php @@ -6,20 +6,20 @@ class DeleteProvider { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $providerId) + public function delete(int $providerId) :bool { $sql = "DELETE FROM `Instace_Type_Providers` WHERE `ITP_ID` = :providerId"; $do = $this->database->prepare($sql); $do->execute([ ":providerId"=>$providerId ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Instances/InstanceTypes/Providers/InsertProvider.php b/src/classes/Model/Instances/InstanceTypes/Providers/InsertProvider.php index 89b8fcaf..d9ee6c75 100644 --- a/src/classes/Model/Instances/InstanceTypes/Providers/InsertProvider.php +++ b/src/classes/Model/Instances/InstanceTypes/Providers/InsertProvider.php @@ -6,20 +6,20 @@ class InsertProvider { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(string $name) + public function insert(string $name) :bool { $sql = "INSERT INTO `Instace_Type_Providers`(`ITP_Name`) VALUES (:name)"; $do = $this->database->prepare($sql); $do->execute([ ":name"=>$name ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Instances/Settings/GetSettings.php b/src/classes/Model/Instances/Settings/GetSettings.php index ad034439..7260c824 100644 --- a/src/classes/Model/Instances/Settings/GetSettings.php +++ b/src/classes/Model/Instances/Settings/GetSettings.php @@ -6,7 +6,7 @@ class GetSettings { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Metrics/DeleteMetrics.php b/src/classes/Model/Metrics/DeleteMetrics.php index 146c1261..ca94dd8c 100644 --- a/src/classes/Model/Metrics/DeleteMetrics.php +++ b/src/classes/Model/Metrics/DeleteMetrics.php @@ -6,14 +6,14 @@ class DeleteMetrics { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteForInstance(int $hostId, string $instance, string $project) + public function deleteForInstance(int $hostId, string $instance, string $project) :bool { $sql = "DELETE FROM `Instance_Metric_Values` @@ -33,7 +33,7 @@ public function deleteForInstance(int $hostId, string $instance, string $project return $do->rowCount() ? true : false; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `Instance_Metric_Values` @@ -47,7 +47,7 @@ public function deleteForHost(int $hostId) return $do->rowCount() ? true : false; } - public function deleteByIds(array $ids) + public function deleteByIds(array $ids) :bool { $qMarks = join(',', array_fill(0, count($ids), '?')); $sql = "DELETE FROM @@ -60,7 +60,7 @@ public function deleteByIds(array $ids) return $do->rowCount() ? true : false; } - public function deleteBefore(\DateTimeInterface $before) + public function deleteBefore(\DateTimeInterface $before) :bool { $sql = "DELETE FROM `Instance_Metric_Values` diff --git a/src/classes/Model/Metrics/FetchMetrics.php b/src/classes/Model/Metrics/FetchMetrics.php index 173b95f8..e1e6d8d6 100644 --- a/src/classes/Model/Metrics/FetchMetrics.php +++ b/src/classes/Model/Metrics/FetchMetrics.php @@ -6,7 +6,7 @@ class FetchMetrics { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Metrics/InsertMetric.php b/src/classes/Model/Metrics/InsertMetric.php index 9d263b7d..dbf88562 100644 --- a/src/classes/Model/Metrics/InsertMetric.php +++ b/src/classes/Model/Metrics/InsertMetric.php @@ -6,14 +6,14 @@ class InsertMetric { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(string $date, int $hostId, string $containerName, int $typeId, string $data) + public function insert(string $date, int $hostId, string $containerName, int $typeId, string $data) :bool { $sql = "INSERT INTO `Instance_Metric_Values` ( diff --git a/src/classes/Model/Metrics/Types/FetchType.php b/src/classes/Model/Metrics/Types/FetchType.php index 6420b8a3..f9736842 100644 --- a/src/classes/Model/Metrics/Types/FetchType.php +++ b/src/classes/Model/Metrics/Types/FetchType.php @@ -6,7 +6,7 @@ class FetchType { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/ProjectAnalytics/DeleteAnalytics.php b/src/classes/Model/ProjectAnalytics/DeleteAnalytics.php index eee75956..bc97db61 100644 --- a/src/classes/Model/ProjectAnalytics/DeleteAnalytics.php +++ b/src/classes/Model/ProjectAnalytics/DeleteAnalytics.php @@ -6,14 +6,14 @@ class DeleteAnalytics { - private $database; + private \PDO $database; public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteBefore(\DateTimeInterface $before) + public function deleteBefore(\DateTimeInterface $before) :bool { $sql = "DELETE FROM `Project_Analytics` @@ -27,7 +27,7 @@ public function deleteBefore(\DateTimeInterface $before) return $do->rowCount() ? true : false; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `Project_Analytics` diff --git a/src/classes/Model/ProjectAnalytics/FetchAnalytics.php b/src/classes/Model/ProjectAnalytics/FetchAnalytics.php index 0e52edab..5ceac6d1 100644 --- a/src/classes/Model/ProjectAnalytics/FetchAnalytics.php +++ b/src/classes/Model/ProjectAnalytics/FetchAnalytics.php @@ -6,7 +6,7 @@ class FetchAnalytics { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/ProjectAnalytics/InsertAnalytic.php b/src/classes/Model/ProjectAnalytics/InsertAnalytic.php index d858ba45..9682ec5b 100644 --- a/src/classes/Model/ProjectAnalytics/InsertAnalytic.php +++ b/src/classes/Model/ProjectAnalytics/InsertAnalytic.php @@ -6,8 +6,8 @@ class InsertAnalytic { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; @@ -20,7 +20,7 @@ public function insert( int $typeId, int $value, ?int $limit - ) { + ) :bool { $sql = "INSERT INTO `Project_Analytics` ( `PA_Date_Created`, `PA_Host_ID`, diff --git a/src/classes/Model/ProjectAnalytics/Types/FetchProjectAnalyticsTypes.php b/src/classes/Model/ProjectAnalytics/Types/FetchProjectAnalyticsTypes.php index d9085181..4204f52f 100644 --- a/src/classes/Model/ProjectAnalytics/Types/FetchProjectAnalyticsTypes.php +++ b/src/classes/Model/ProjectAnalytics/Types/FetchProjectAnalyticsTypes.php @@ -6,7 +6,7 @@ class FetchProjectAnalyticsTypes { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/AllowedProjects/DeleteUserAccess.php b/src/classes/Model/Users/AllowedProjects/DeleteUserAccess.php index fc1a4187..51dc9d71 100644 --- a/src/classes/Model/Users/AllowedProjects/DeleteUserAccess.php +++ b/src/classes/Model/Users/AllowedProjects/DeleteUserAccess.php @@ -6,14 +6,14 @@ class DeleteUserAccess { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $userId, int $hostId, string $project) + public function delete(int $userId, int $hostId, string $project) :bool { $sql = "DELETE FROM `User_Allowed_Projects` WHERE @@ -30,10 +30,10 @@ public function delete(int $userId, int $hostId, string $project) ":hostId"=>$hostId, ":project"=>$project ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } - public function deletAllForProject(int $hostId, string $project) + public function deletAllForProject(int $hostId, string $project) :bool { $sql = "DELETE FROM `User_Allowed_Projects` WHERE @@ -47,10 +47,10 @@ public function deletAllForProject(int $hostId, string $project) ":hostId"=>$hostId, ":project"=>$project ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `User_Allowed_Projects` WHERE @@ -60,9 +60,9 @@ public function deleteForHost(int $hostId) $do->execute([ ":hostId"=>$hostId ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } - public function deleteForUser(int $targetUserId) + public function deleteForUser(int $targetUserId) :bool { $sql = "DELETE FROM `User_Allowed_Projects` WHERE @@ -72,6 +72,6 @@ public function deleteForUser(int $targetUserId) $do->execute([ ":targetUserId"=>$targetUserId ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Users/AllowedProjects/FetchAllowedProjects.php b/src/classes/Model/Users/AllowedProjects/FetchAllowedProjects.php index 6aaa6545..c671d58e 100644 --- a/src/classes/Model/Users/AllowedProjects/FetchAllowedProjects.php +++ b/src/classes/Model/Users/AllowedProjects/FetchAllowedProjects.php @@ -6,7 +6,7 @@ class FetchAllowedProjects { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/AllowedProjects/InsertUserAccess.php b/src/classes/Model/Users/AllowedProjects/InsertUserAccess.php index 1a991dee..4fb33308 100644 --- a/src/classes/Model/Users/AllowedProjects/InsertUserAccess.php +++ b/src/classes/Model/Users/AllowedProjects/InsertUserAccess.php @@ -6,14 +6,14 @@ class InsertUserAccess { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $grantedBy, int $userId, int $hostId, string $project) + public function insert(int $grantedBy, int $userId, int $hostId, string $project) :bool { $sql = "INSERT INTO `User_Allowed_Projects`( `UAP_Granted_By`, @@ -33,6 +33,6 @@ public function insert(int $grantedBy, int $userId, int $hostId, string $project ":hostId"=>$hostId, ":project"=>$project ]); - return $do->rowCount() ? true : false; + return $do->rowCount() ? true : false; } } diff --git a/src/classes/Model/Users/ApiTokens/DeleteUserApiTokens.php b/src/classes/Model/Users/ApiTokens/DeleteUserApiTokens.php index cef543c6..95a0c103 100644 --- a/src/classes/Model/Users/ApiTokens/DeleteUserApiTokens.php +++ b/src/classes/Model/Users/ApiTokens/DeleteUserApiTokens.php @@ -6,14 +6,14 @@ class DeleteUserApiTokens { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function deleteAllNonPermanent(int $userId) + public function deleteAllNonPermanent(int $userId) :bool { $sql = "DELETE FROM `User_Api_Tokens` WHERE @@ -28,7 +28,7 @@ public function deleteAllNonPermanent(int $userId) return $do->rowCount() ? true : false; } - public function deleteAllPermanent(int $userId) + public function deleteAllPermanent(int $userId) :bool { $sql = "DELETE FROM `User_Api_Tokens` WHERE diff --git a/src/classes/Model/Users/Dashboard/DeleteUserDashboard.php b/src/classes/Model/Users/Dashboard/DeleteUserDashboard.php index 7dce4b06..587c95ff 100644 --- a/src/classes/Model/Users/Dashboard/DeleteUserDashboard.php +++ b/src/classes/Model/Users/Dashboard/DeleteUserDashboard.php @@ -6,14 +6,14 @@ class DeleteUserDashboard { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $dashboardId) + public function delete(int $dashboardId) :bool { $sql = "DELETE FROM `User_Dashboards` diff --git a/src/classes/Model/Users/Dashboard/FetchUserDashboards.php b/src/classes/Model/Users/Dashboard/FetchUserDashboards.php index 643bbe5b..ee3e0b74 100644 --- a/src/classes/Model/Users/Dashboard/FetchUserDashboards.php +++ b/src/classes/Model/Users/Dashboard/FetchUserDashboards.php @@ -6,7 +6,7 @@ class FetchUserDashboards { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/Dashboard/Graphs/DeleteDashboardGraph.php b/src/classes/Model/Users/Dashboard/Graphs/DeleteDashboardGraph.php index e9c04c4a..40c68514 100644 --- a/src/classes/Model/Users/Dashboard/Graphs/DeleteDashboardGraph.php +++ b/src/classes/Model/Users/Dashboard/Graphs/DeleteDashboardGraph.php @@ -6,14 +6,14 @@ class DeleteDashboardGraph { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function delete(int $graphId) + public function delete(int $graphId) :bool { $sql = "DELETE FROM `User_Dashboard_Graphs` diff --git a/src/classes/Model/Users/Dashboard/Graphs/FetchDashboardGraphs.php b/src/classes/Model/Users/Dashboard/Graphs/FetchDashboardGraphs.php index 441d2889..9eb1ecec 100644 --- a/src/classes/Model/Users/Dashboard/Graphs/FetchDashboardGraphs.php +++ b/src/classes/Model/Users/Dashboard/Graphs/FetchDashboardGraphs.php @@ -6,7 +6,7 @@ class FetchDashboardGraphs { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/Dashboard/Graphs/InsertDashboardGraph.php b/src/classes/Model/Users/Dashboard/Graphs/InsertDashboardGraph.php index 9774adce..630689c9 100644 --- a/src/classes/Model/Users/Dashboard/Graphs/InsertDashboardGraph.php +++ b/src/classes/Model/Users/Dashboard/Graphs/InsertDashboardGraph.php @@ -6,8 +6,8 @@ class InsertDashboardGraph { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; @@ -21,7 +21,7 @@ public function insert( int $metricId, string $filter, string $range - ) { + ) :bool { $sql = "INSERT INTO `User_Dashboard_Graphs` ( `UDG_UD_ID`, diff --git a/src/classes/Model/Users/Dashboard/InsertUserDashboard.php b/src/classes/Model/Users/Dashboard/InsertUserDashboard.php index 3dbde21d..ea38062f 100644 --- a/src/classes/Model/Users/Dashboard/InsertUserDashboard.php +++ b/src/classes/Model/Users/Dashboard/InsertUserDashboard.php @@ -6,14 +6,14 @@ class InsertUserDashboard { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(int $userId, string $name) + public function insert(int $userId, string $name) :bool { $sql = "INSERT INTO `User_Dashboards` ( diff --git a/src/classes/Model/Users/FetchTokens.php b/src/classes/Model/Users/FetchTokens.php index ef31e24a..3a4394f6 100644 --- a/src/classes/Model/Users/FetchTokens.php +++ b/src/classes/Model/Users/FetchTokens.php @@ -6,7 +6,7 @@ class FetchTokens { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/FetchUserDetails.php b/src/classes/Model/Users/FetchUserDetails.php index f7b63cf9..6a3f878d 100644 --- a/src/classes/Model/Users/FetchUserDetails.php +++ b/src/classes/Model/Users/FetchUserDetails.php @@ -6,14 +6,14 @@ class FetchUserDetails { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function adminPasswordBlank() + public function adminPasswordBlank() :bool { $sql = "SELECT 1 @@ -94,7 +94,7 @@ public function isAdmin(int $userId) return $do->fetchColumn(); } - public function isFromLdap(int $userId) + public function isFromLdap(int $userId) :bool { $sql = "SELECT 1 @@ -111,7 +111,7 @@ public function isFromLdap(int $userId) ]); return $do->fetch() ? true : false; } - public function isLoginDisabled(int $userId) + public function isLoginDisabled(int $userId) :bool { $sql = "SELECT 1 diff --git a/src/classes/Model/Users/FetchUsers.php b/src/classes/Model/Users/FetchUsers.php index 27f94381..e8867d68 100644 --- a/src/classes/Model/Users/FetchUsers.php +++ b/src/classes/Model/Users/FetchUsers.php @@ -6,7 +6,7 @@ class FetchUsers { - private $database; + private \PDO $database; public function __construct(Database $database) { diff --git a/src/classes/Model/Users/InsertToken.php b/src/classes/Model/Users/InsertToken.php index 5e844a14..d4ad49e6 100644 --- a/src/classes/Model/Users/InsertToken.php +++ b/src/classes/Model/Users/InsertToken.php @@ -6,14 +6,14 @@ class InsertToken { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(string $userId, string $token, int $permanent = 0) + public function insert(int $userId, string $token, int $permanent = 0) :bool { $sql = "INSERT INTO `User_Api_Tokens` ( diff --git a/src/classes/Model/Users/InsertUser.php b/src/classes/Model/Users/InsertUser.php index 2754f336..1f63b6e2 100644 --- a/src/classes/Model/Users/InsertUser.php +++ b/src/classes/Model/Users/InsertUser.php @@ -6,14 +6,14 @@ class InsertUser { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function insert(string $username, string $passwordHash, $ldapId = null) + public function insert(string $username, string $passwordHash, string $ldapId = null) :bool { $sql = "INSERT INTO `Users` ( @@ -35,8 +35,12 @@ public function insert(string $username, string $passwordHash, $ldapId = null) return $do->rowCount() ? true : false; } - public function getId() + public function getId() :int { - return $this->database->lastInsertId(); + $newUserId = $this->database->lastInsertId(); + if ($newUserId === false) { + throw new \Exception("User wasn't created successfully", 1); + } + return (int) $newUserId; } } diff --git a/src/classes/Model/Users/InvalidateToken.php b/src/classes/Model/Users/InvalidateToken.php index 7ced56a8..9e5d518c 100644 --- a/src/classes/Model/Users/InvalidateToken.php +++ b/src/classes/Model/Users/InvalidateToken.php @@ -6,14 +6,14 @@ class InvalidateToken { - private $database; + private \PDO $database; public function __construct(Database $database) { $this->database = $database->dbObject; } - public function invalidate(int $userId, string $token) + public function invalidate(int $userId, string $token) :bool { $sql = "DELETE FROM `User_Api_Tokens` @@ -21,13 +21,12 @@ public function invalidate(int $userId, string $token) `UAT_Token` = :token AND `UAT_User_ID` = :user_id - AND - `UAT_Permanent` = 0" - ; + AND + `UAT_Permanent` = 0"; $do = $this->database->prepare($sql); $do->execute([ - ":user_id" => $userId, - ":token" => $token + ":user_id"=>$userId, + ":token"=>$token ]); return $do->rowCount() ? true : false; } diff --git a/src/classes/Model/Users/Projects/DeleteUserProject.php b/src/classes/Model/Users/Projects/DeleteUserProject.php index ac8986a8..abd1159d 100644 --- a/src/classes/Model/Users/Projects/DeleteUserProject.php +++ b/src/classes/Model/Users/Projects/DeleteUserProject.php @@ -6,14 +6,14 @@ class DeleteUserProject { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function removeFromProject(int $userId, int $hostId, string $project) + public function removeFromProject(int $userId, int $hostId, string $project) :bool { $sql = "DELETE FROM `User_Host_Projects` @@ -33,7 +33,7 @@ public function removeFromProject(int $userId, int $hostId, string $project) return $do->rowCount() ? true : false; } - public function deleteForHost(int $hostId) + public function deleteForHost(int $hostId) :bool { $sql = "DELETE FROM `User_Host_Projects` @@ -47,7 +47,7 @@ public function deleteForHost(int $hostId) return $do->rowCount() ? true : false; } - public function removeAllUsersFromProject(int $hostId, string $project) + public function removeAllUsersFromProject(int $hostId, string $project) :bool { $sql = "DELETE FROM `User_Host_Projects` diff --git a/src/classes/Model/Users/Projects/FetchUserProject.php b/src/classes/Model/Users/Projects/FetchUserProject.php index 78dba44f..670c64fe 100644 --- a/src/classes/Model/Users/Projects/FetchUserProject.php +++ b/src/classes/Model/Users/Projects/FetchUserProject.php @@ -6,14 +6,14 @@ class FetchUserProject { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function fetch(int $userId, int $hostId) + public function fetch(int $userId, int $hostId) :string { $sql = "SELECT `UHP_Project` @@ -32,7 +32,7 @@ public function fetch(int $userId, int $hostId) return $do->fetchColumn(); } - public function fetchCurrentProjects(int $userId) + public function fetchCurrentProjects(int $userId) :array { $sql = "SELECT `UHP_Host_ID`, diff --git a/src/classes/Model/Users/Projects/InsertUserProject.php b/src/classes/Model/Users/Projects/InsertUserProject.php index f5983a8b..787b3323 100644 --- a/src/classes/Model/Users/Projects/InsertUserProject.php +++ b/src/classes/Model/Users/Projects/InsertUserProject.php @@ -6,14 +6,14 @@ class InsertUserProject { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function putUsersOnProjectToProject(int $hostId, string $oldProject, string $newProject) + public function putUsersOnProjectToProject(int $hostId, string $oldProject, string $newProject) :bool { $sql = "UPDATE `User_Host_Projects` @@ -33,7 +33,7 @@ public function putUsersOnProjectToProject(int $hostId, string $oldProject, stri return $do->rowCount() ? true : false; } - public function insert(int $userId, int $hostId, string $project) + public function insert(int $userId, int $hostId, string $project) :bool { $mod = isset($_ENV["DB_SQLITE"]) && !empty($_ENV["DB_SQLITE"]) ? "CONFLICT(UHP_User_ID, UHP_Host_ID) DO UPDATE SET UHP_Project = :project;" : "DUPLICATE KEY UPDATE `UHP_Project` = :project"; $sql = "INSERT INTO `User_Host_Projects`( diff --git a/src/classes/Model/Users/RemoveToken.php b/src/classes/Model/Users/RemoveToken.php index b4296b84..16f11d80 100644 --- a/src/classes/Model/Users/RemoveToken.php +++ b/src/classes/Model/Users/RemoveToken.php @@ -6,14 +6,14 @@ class RemoveToken { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function remove(int $tokenId) + public function remove(int $tokenId) :bool { $sql = "DELETE FROM `User_Api_Tokens` diff --git a/src/classes/Model/Users/UpdateAdminStatus.php b/src/classes/Model/Users/UpdateAdminStatus.php index fcb5c9c9..ad3a2663 100644 --- a/src/classes/Model/Users/UpdateAdminStatus.php +++ b/src/classes/Model/Users/UpdateAdminStatus.php @@ -6,14 +6,14 @@ class UpdateAdminStatus { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function update(int $userId, int $status) + public function update(int $userId, int $status) :bool { $sql = "UPDATE `Users` diff --git a/src/classes/Model/Users/UpdateLoginStatus.php b/src/classes/Model/Users/UpdateLoginStatus.php index fa2f1ecd..41753a0d 100644 --- a/src/classes/Model/Users/UpdateLoginStatus.php +++ b/src/classes/Model/Users/UpdateLoginStatus.php @@ -6,14 +6,14 @@ class UpdateLoginStatus { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function update(int $userId, int $status = null) + public function update(int $userId, int $status = null) :bool { $sql = "UPDATE `Users` diff --git a/src/classes/Model/Users/UpdatePasswordHash.php b/src/classes/Model/Users/UpdatePasswordHash.php index 91fdd1df..b6a6eb8d 100644 --- a/src/classes/Model/Users/UpdatePasswordHash.php +++ b/src/classes/Model/Users/UpdatePasswordHash.php @@ -6,14 +6,14 @@ class UpdatePasswordHash { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function update(int $userId, string $passwordHash) + public function update(int $userId, string $passwordHash) :bool { $sql = "UPDATE `Users` diff --git a/src/classes/Model/Users/UpdateUserDeletedStatus.php b/src/classes/Model/Users/UpdateUserDeletedStatus.php index 6ce5cc61..8aca7c27 100644 --- a/src/classes/Model/Users/UpdateUserDeletedStatus.php +++ b/src/classes/Model/Users/UpdateUserDeletedStatus.php @@ -6,14 +6,14 @@ class UpdateUserDeletedStatus { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function setDeleted(int $userId, int $targetUserId) + public function setDeleted(int $userId, int $targetUserId) :bool { $sql = "UPDATE `Users` diff --git a/src/classes/Model/Users/UpdateUsername.php b/src/classes/Model/Users/UpdateUsername.php index 057d6316..2e389c03 100644 --- a/src/classes/Model/Users/UpdateUsername.php +++ b/src/classes/Model/Users/UpdateUsername.php @@ -6,14 +6,14 @@ class UpdateUsername { - private $database; - + private \PDO $database; + public function __construct(Database $database) { $this->database = $database->dbObject; } - public function update(int $targetUserId, string $name) + public function update(int $targetUserId, string $name) :bool { $sql = "UPDATE `Users` diff --git a/src/classes/Objects/Host.php b/src/classes/Objects/Host.php index 6f6ae304..9a58aec5 100644 --- a/src/classes/Objects/Host.php +++ b/src/classes/Objects/Host.php @@ -5,30 +5,41 @@ use dhope0000\LXDClient\Model\Client\LxdClient; use Opensaucesystems\Lxd\Client; +/** + * @property-read \Opensaucesystems\Lxd\Endpoint\Storage $storage + * @property-read \Opensaucesystems\Lxd\Endpoint\Images $images + * @property-read \Opensaucesystems\Lxd\Endpoint\Projects $projects + * @property-read \Opensaucesystems\Lxd\Endpoint\Profiles $profiles + * @property-read \Opensaucesystems\Lxd\Endpoint\InstaceBase $instances. + * @property-read \Opensaucesystems\Lxd\Endpoint\Networks $networks. + * @property-read \Opensaucesystems\Lxd\Endpoint\Volumes $volumes. + * @property-read \Opensaucesystems\Lxd\Endpoint\Resources $resources. + * @property-read \Opensaucesystems\Lxd\Endpoint\Host $host. + * @property-read \Opensaucesystems\Lxd\Endpoint\Certificates $certificates.. + * @property-read \Opensaucesystems\Lxd\Endpoint\Warnings $warnings.. + */ class Host implements \JsonSerializable { - private $id; - private $urlAndPort; - private $certPath; - private $alias; - - private $certFilePath; - private $keyFilePath ; - private $hostOnline; - - private $supportsLoadAvgs; - - private $customProps = []; - - private $lxdClient; - private $client = null; + private ?int $id; + private ?string $urlAndPort; + private ?string $certPath; + private ?string $alias; + private ?string $certFilePath; + private ?string $keyFilePath ; + private ?int $hostOnline; + private ?string $socketPath; + private ?int $supportsLoadAvgs; + private array $customProps = []; + + private ?LxdClient $lxdClient; + private ?Client $client = null; public function __construct(LxdClient $lxdClient) { $this->lxdClient = $lxdClient; } - public function setCustomProp(string $name, $value) + public function setCustomProp(string $name, $value) :void { if (in_array($name, ["hostId", "alias", "urlAndPort"])) { throw new \Exception("Not to set $name is custom props", 1); @@ -36,12 +47,12 @@ public function setCustomProp(string $name, $value) $this->customProps[$name] = $value; } - public function getCustomProp(string $name) + public function getCustomProp(string $name) :array { return $this->customProps[$name]; } - public function removeCustomProp(string $name) + public function removeCustomProp(string $name) :void { unset($this->customProps[$name]); } @@ -71,12 +82,17 @@ public function getAlias() :string return $this->alias; } + public function getSocketPath() + { + return $this->socketPath; + } + public function hostSupportLoadAvgs() :bool { return (bool) $this->supportsLoadAvgs; } - public function callClientMethod($method, $param = null) + public function callClientMethod(string $method, $param = null) { if ($param !== null) { return $this->getClient()->$method($param); @@ -85,7 +101,7 @@ public function callClientMethod($method, $param = null) } } - final public function jsonSerialize() + final public function jsonSerialize() :array { return array_merge([ "hostId"=>$this->id, @@ -93,7 +109,8 @@ final public function jsonSerialize() "urlAndPort"=>$this->urlAndPort, "hostOnline"=>$this->hostOnline, "supportsLoadAvgs"=>$this->supportsLoadAvgs, - "currentProject"=>$this->getProject() + "currentProject"=>$this->getProject(), + "socketPath"=>$this->socketPath ], $this->customProps); } /** @@ -107,7 +124,7 @@ public function getClient() :Client return $this->client; } - public function setProject(string $project) + public function setProject(string $project) :void { if ($this->client == null) { $this->client = $this->lxdClient->getClientWithHost($this); @@ -115,7 +132,7 @@ public function setProject(string $project) $this->client->setProject($project); } - public function getProject() + public function getProject() :string { if ($this->client == null) { $this->client = $this->lxdClient->getClientWithHost($this); @@ -123,12 +140,12 @@ public function getProject() return $this->client->getProject(); } - public function __set($prop, $value) + public function __set(string $prop, $value) { throw new \Exception("Not allowed to set public properties on this object, use get/set/removeCustomProp", 1); } - public function __get($target) + public function __get(string $target) { return $this->getClient()->$target; } diff --git a/src/classes/Objects/HostsCollection.php b/src/classes/Objects/HostsCollection.php index f9f7c6b6..5d095306 100644 --- a/src/classes/Objects/HostsCollection.php +++ b/src/classes/Objects/HostsCollection.php @@ -6,9 +6,15 @@ class HostsCollection implements \Iterator, \JsonSerializable { + /** + * @var array<\dhope0000\LXDClient\Objects\Host> + */ private $hosts = []; private $index = 0; + /** + * @param array<\dhope0000\LXDClient\Objects\Host> $hosts + */ public function __construct(array $hosts) { foreach ($hosts as $host) { @@ -20,7 +26,9 @@ final public function jsonSerialize() { return $this->hosts; } - + /** + * @param \dhope0000\LXDClient\Objects\Host $host + */ public function addHost(Host $host) { $this->hosts[] = $host; diff --git a/src/classes/Objects/RecordedAction.php b/src/classes/Objects/RecordedAction.php index e7f84966..1f82ba10 100644 --- a/src/classes/Objects/RecordedAction.php +++ b/src/classes/Objects/RecordedAction.php @@ -4,10 +4,10 @@ class RecordedAction implements \JsonSerializable { - private $title; - private $date; - private $category; - private $method; + private string $title; + private DateTimeInterface $date; + private string $category; + private string $method; public function __construct(string $title, \DateTimeInterface $date, string $category, string $method) { @@ -17,12 +17,12 @@ public function __construct(string $title, \DateTimeInterface $date, string $cat $this->method = $method; } - public function __set($prop, $value) + public function __set(string $prop, $value) { throw new \Exception("Not allowed to set public properties on this object, use get/set/removeCustomProp", 1); } - public function jsonSerialize() + public function jsonSerialize() :array { return [ "title"=>$this->title, @@ -30,17 +30,17 @@ public function jsonSerialize() ]; } - public function getTitle() + public function getTitle() :string { return $this->title; } - public function getCategory() + public function getCategory() :string { return $this->category; } - public function getMethod() + public function getMethod() :string { return $this->method; } diff --git a/src/classes/Objects/RouteToNameMapping.php b/src/classes/Objects/RouteToNameMapping.php index 2b306c42..de6aeed3 100644 --- a/src/classes/Objects/RouteToNameMapping.php +++ b/src/classes/Objects/RouteToNameMapping.php @@ -4,7 +4,7 @@ class RouteToNameMapping { - public $routesToName = array ( + public array $routesToName = array( 'dhope0000\\LXDClient\\Controllers\\ProjectAnalytics\\GetGraphableProjectAnalyticsController\\get' => 'Get graphable analytics', 'dhope0000\\LXDClient\\Controllers\\Profiles\\GetProfileController\\get' => 'Get Profile', 'dhope0000\\LXDClient\\Controllers\\Profiles\\DeleteProfileController\\delete' => 'Delete Profile', @@ -91,11 +91,11 @@ class RouteToNameMapping 'dhope0000\\LXDClient\\Controllers\\Images\\ImportLinuxContainersByAliasController\\import' => 'Import LinunxContainer.Org Image', ); - public function getControllerName(string $controller) + public function getControllerName(string $controller) :string { if (!isset($this->routesToName[$controller])) { return ""; } return $this->routesToName[$controller]; } -} \ No newline at end of file +} diff --git a/src/classes/Tools/Analytics/DownloadHistory.php b/src/classes/Tools/Analytics/DownloadHistory.php index 5ef50f62..5b9bb590 100644 --- a/src/classes/Tools/Analytics/DownloadHistory.php +++ b/src/classes/Tools/Analytics/DownloadHistory.php @@ -7,9 +7,9 @@ class DownloadHistory { - private $validatePermissions; - private $fetchLatestData; - + private ValidatePermissions $validatePermissions; + private FetchLatestData $fetchLatestData; + public function __construct( ValidatePermissions $validatePermissions, FetchLatestData $fetchLatestData @@ -18,7 +18,7 @@ public function __construct( $this->fetchLatestData = $fetchLatestData; } - public function download(int $userId) + public function download(int $userId) :array { $this->validatePermissions->isAdminOrThrow($userId); return $this->fetchLatestData->fetchAll(); diff --git a/src/classes/Tools/Backups/EnforceRetentionRules.php b/src/classes/Tools/Backups/EnforceRetentionRules.php index 0c3dbfd0..5cd091ff 100644 --- a/src/classes/Tools/Backups/EnforceRetentionRules.php +++ b/src/classes/Tools/Backups/EnforceRetentionRules.php @@ -11,11 +11,11 @@ class EnforceRetentionRules { - private $fetchBackupSchedules; - private $fetchInstanceBackups; - private $deleteLocalBackup; - private $fetchUsers; - + private FetchBackupSchedules $fetchBackupSchedules; + private FetchInstanceBackups $fetchInstanceBackups; + private DeleteLocalBackup $deleteLocalBackup; + private FetchUsers $fetchUsers; + public function __construct( FetchInstanceBackups $fetchInstanceBackups, FetchBackupSchedules $fetchBackupSchedules, @@ -28,7 +28,7 @@ public function __construct( $this->fetchUsers = $fetchUsers; } - public function enforce() + public function enforce() :void { $hostBackups = $this->fetchBackupSchedules->fetchActiveSchedsGroupedByHostId(); diff --git a/src/classes/Tools/Backups/GetBackupsOverview.php b/src/classes/Tools/Backups/GetBackupsOverview.php index 7d869f9f..01ca4fe3 100644 --- a/src/classes/Tools/Backups/GetBackupsOverview.php +++ b/src/classes/Tools/Backups/GetBackupsOverview.php @@ -8,9 +8,9 @@ class GetBackupsOverview { - private $fetchBackups; - private $getHostInstanceStatusForBackupSet; - private $fetchUserDetails; + private FetchBackups $fetchBackups; + private GetHostInstanceStatusForBackupSet $getHostInstanceStatusForBackupSet; + private FetchUserDetails $fetchUserDetails; public function __construct( FetchBackups $fetchBackups, @@ -22,7 +22,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function get($userId) + public function get(int $userId) :array { if ($this->fetchUserDetails->isAdmin($userId)) { $allBackups = $this->fetchBackups->fetchAll(); @@ -41,7 +41,7 @@ public function get($userId) ]; } - private function getProperties(array $backups) + private function getProperties(array $backups) :array { $sizeByMonthYear = []; $filesByMonthYear = []; @@ -52,8 +52,8 @@ private function getProperties(array $backups) $year = $date->format("Y"); if (!isset($sizeByMonthYear[$year])) { - $this->createYearArray($sizeByMonthYear, $year); - $this->createYearArray($filesByMonthYear, $year); + $this->createYearArray($sizeByMonthYear, (int) $year); + $this->createYearArray($filesByMonthYear, (int) $year); } @@ -81,7 +81,7 @@ private function getProperties(array $backups) ]; } - private function createYearArray(&$array, $year) + private function createYearArray(array &$array, int $year) :void { $array[$year] = array_fill(1, 12, null); } diff --git a/src/classes/Tools/Backups/GetHostInstanceStatusForBackupSet.php b/src/classes/Tools/Backups/GetHostInstanceStatusForBackupSet.php index f5a9d51d..289b42d0 100644 --- a/src/classes/Tools/Backups/GetHostInstanceStatusForBackupSet.php +++ b/src/classes/Tools/Backups/GetHostInstanceStatusForBackupSet.php @@ -2,30 +2,23 @@ namespace dhope0000\LXDClient\Tools\Backups; -use dhope0000\LXDClient\Model\Client\LxdClient; -use dhope0000\LXDClient\Tools\Instances\GetHostsInstances; use dhope0000\LXDClient\Model\Hosts\Backups\Instances\Schedules\FetchBackupSchedules; use dhope0000\LXDClient\Tools\Universe; use dhope0000\LXDClient\Tools\Hosts\HasExtension; use dhope0000\LXDClient\Constants\LxdApiExtensions; +use dhope0000\LXDClient\Objects\Host; class GetHostInstanceStatusForBackupSet { - private $getHostsInstances; - private $lxdClient; - private $fetchBackupSchedules; - private $universe; - private $hasExtension; + private FetchBackupSchedules $fetchBackupSchedules; + private Universe $universe; + private HasExtension $hasExtension; public function __construct( - GetHostsInstances $getHostsInstances, - LxdClient $lxdClient, FetchBackupSchedules $fetchBackupSchedules, HasExtension $hasExtension, Universe $universe ) { - $this->getHostsInstances = $getHostsInstances; - $this->lxdClient = $lxdClient; $this->fetchBackupSchedules = $fetchBackupSchedules; $this->universe = $universe; $this->hasExtension = $hasExtension; @@ -58,7 +51,7 @@ public function get(int $userId, array $backups) return $missingBackups; } - private function addDetailsToHost($host, $backupsByHostId, $groupedSchedule) + private function addDetailsToHost(Host $host, array $backupsByHostId, array $groupedSchedule) { $backupsToSearch = []; @@ -139,7 +132,7 @@ private function addDetailsToHost($host, $backupsByHostId, $groupedSchedule) return $host; } - private function createBackupsByHostIdStruct(array $backups) + private function createBackupsByHostIdStruct(array $backups) :array { $backupsByHostId = []; foreach ($backups as $backup) { @@ -151,7 +144,7 @@ private function createBackupsByHostIdStruct(array $backups) return $backupsByHostId; } - private function findAllBackupsandTotalSize(string $container, array $hostBackups) + private function findAllBackupsandTotalSize(string $container, array $hostBackups) :array { $output = []; $totalSize = 0; @@ -167,7 +160,7 @@ private function findAllBackupsandTotalSize(string $container, array $hostBackup ]; } - private function findLastBackup(string $project, string $container, ?array $hostBackups) + private function findLastBackup(string $project, string $container, ?array $hostBackups) :array { $x = [ "neverBackedUp"=>true @@ -191,7 +184,7 @@ private function findLastBackup(string $project, string $container, ?array $host return $x; } - private function groupSchedules(array $schedules) + private function groupSchedules(array $schedules) :array { foreach ($schedules as $hostId => $instances) { foreach ($instances as $index => $instance) { diff --git a/src/classes/Tools/Backups/RemoveBackupHistory.php b/src/classes/Tools/Backups/RemoveBackupHistory.php index 5a5fc3c9..75e9882c 100644 --- a/src/classes/Tools/Backups/RemoveBackupHistory.php +++ b/src/classes/Tools/Backups/RemoveBackupHistory.php @@ -8,8 +8,8 @@ class RemoveBackupHistory { - private $getSetting; - private $deleteBackup; + private GetSetting $getSetting; + private DeleteBackup $deleteBackup; public function __construct( GetSetting $getSetting, @@ -19,7 +19,7 @@ public function __construct( $this->deleteBackup = $deleteBackup; } - public function remove() + public function remove() :void { $howFarBack = $this->getSetting->getSettingLatestValue(InstanceSettingsKeys::BACKUP_HISTORY); $before = (new \DateTime())->modify($howFarBack); diff --git a/src/classes/Tools/Backups/RestoreBackup.php b/src/classes/Tools/Backups/RestoreBackup.php index aa12a6ec..393bb00b 100644 --- a/src/classes/Tools/Backups/RestoreBackup.php +++ b/src/classes/Tools/Backups/RestoreBackup.php @@ -8,8 +8,8 @@ class RestoreBackup { - private $fetchBackup; - private $validatePermissions; + private FetchBackup $fetchBackup; + private ValidatePermissions $validatePermissions; public function __construct( FetchBackup $fetchBackup, diff --git a/src/classes/Tools/Backups/Schedule/BackupStringToObject.php b/src/classes/Tools/Backups/Schedule/BackupStringToObject.php index 99f4d09a..3d972bee 100644 --- a/src/classes/Tools/Backups/Schedule/BackupStringToObject.php +++ b/src/classes/Tools/Backups/Schedule/BackupStringToObject.php @@ -6,12 +6,12 @@ class BackupStringToObject { - public function trimString($data) + public function trimString($data) :string { return trim($data); } - public function convertStringArrayToPhp($string) + public function convertStringArrayToPhp(string $string) :array { $string = str_replace("[", "", $string); $string = str_replace("]", "", $string); @@ -19,10 +19,10 @@ public function convertStringArrayToPhp($string) } - public function parseString($string) :BackupSchedule + public function parseString(string $string) :BackupSchedule { $this->validateString($string); - + $parts = array_map([$this, "trimString"], explode("~", $string)); $time = $parts[1]; @@ -43,7 +43,7 @@ public function parseString($string) :BackupSchedule $parts[0], $time, $daysOfWeek, - is_numeric($parts[3]) ? $parts[3] : 0 + (int) is_numeric($parts[3]) ? $parts[3] : 0 ); } diff --git a/src/classes/Tools/Backups/Schedule/RemoveDeadBackupSchedules.php b/src/classes/Tools/Backups/Schedule/RemoveDeadBackupSchedules.php index 5db2854f..a7ec8685 100644 --- a/src/classes/Tools/Backups/Schedule/RemoveDeadBackupSchedules.php +++ b/src/classes/Tools/Backups/Schedule/RemoveDeadBackupSchedules.php @@ -8,9 +8,9 @@ class RemoveDeadBackupSchedules { - private $fetchBackupSchedules; - private $getDetails; - private $updateBackupSchedules; + private FetchBackupSchedules $fetchBackupSchedules; + private GetDetails $getDetails; + private UpdateBackupSchedules $updateBackupSchedules; public function __construct( FetchBackupSchedules $fetchBackupSchedules, @@ -22,7 +22,7 @@ public function __construct( $this->updateBackupSchedules = $updateBackupSchedules; } - public function remove() + public function remove() :void { $hostBackups = $this->fetchBackupSchedules->fetchActiveSchedsGroupedByHostId(); foreach ($hostBackups as $hostId => $backups) { diff --git a/src/classes/Tools/Backups/Schedule/ValidateBackupObject.php b/src/classes/Tools/Backups/Schedule/ValidateBackupObject.php index d62b688f..a24cb6dd 100644 --- a/src/classes/Tools/Backups/Schedule/ValidateBackupObject.php +++ b/src/classes/Tools/Backups/Schedule/ValidateBackupObject.php @@ -6,7 +6,7 @@ class ValidateBackupObject { - public function validate(BackupSchedule $schedule) + public function validate(BackupSchedule $schedule) :void { $this->validateRange($schedule); $this->validateTimes($schedule); @@ -15,7 +15,7 @@ public function validate(BackupSchedule $schedule) } - public function validateRange(BackupSchedule $schedule) + public function validateRange(BackupSchedule $schedule) :void { $allowedRange = ["daily", "weekly", "monthly"]; if (!in_array($schedule->getRange(), $allowedRange)) { @@ -23,7 +23,7 @@ public function validateRange(BackupSchedule $schedule) } } - public function validateTimes(BackupSchedule $schedule) + public function validateTimes(BackupSchedule $schedule) :void { $times = $schedule->getTimes(); foreach ($times as $time) { @@ -34,7 +34,7 @@ public function validateTimes(BackupSchedule $schedule) } } - public function validateDaysOfWeek(BackupSchedule $schedule) + public function validateDaysOfWeek(BackupSchedule $schedule) :void { $daysOfWeek = $schedule->getDaysOfWeek(); foreach ($daysOfWeek as $day) { @@ -44,7 +44,7 @@ public function validateDaysOfWeek(BackupSchedule $schedule) } } - public function validateDayOfMonth(BackupSchedule $schedule) + public function validateDayOfMonth(BackupSchedule $schedule) :void { $dayOfMonth = $schedule->getDayOfMonth(); diff --git a/src/classes/Tools/CloudConfig/Contents/GetLatest.php b/src/classes/Tools/CloudConfig/Contents/GetLatest.php index 6e2b0ed8..b1f0edff 100644 --- a/src/classes/Tools/CloudConfig/Contents/GetLatest.php +++ b/src/classes/Tools/CloudConfig/Contents/GetLatest.php @@ -6,14 +6,14 @@ class GetLatest { - private $getConfig; - + private GetConfig $getConfig; + public function __construct(GetConfig $getConfig) { $this->getConfig = $getConfig; } - public function getLatest(int $cloudConfigId) + public function getLatest(int $cloudConfigId) :array { $latest = $this->getConfig->getLatestConfig($cloudConfigId); if (empty($latest)) { @@ -25,14 +25,14 @@ public function getLatest(int $cloudConfigId) "envVariables"=>[] ]; } - + $latest["imageDetails"] = $this->getJsonOrEmptyArray($latest, "imageDetails"); $latest["envVariables"] = $this->getJsonOrEmptyArray($latest, "envVariables"); return $latest; } - private function getJsonOrEmptyArray($array, $key) :array + private function getJsonOrEmptyArray(array $array, string $key) :array { return !empty($array[$key]) ? json_decode($array[$key], true) : []; } diff --git a/src/classes/Tools/CloudConfig/Create.php b/src/classes/Tools/CloudConfig/Create.php index 54b78c1c..efc6e0fa 100644 --- a/src/classes/Tools/CloudConfig/Create.php +++ b/src/classes/Tools/CloudConfig/Create.php @@ -7,8 +7,8 @@ class Create { - private $getCloudConfigs; - private $createConfig; + private GetCloudConfigs $getCloudConfigs; + private CreateConfig $createConfig; public function __construct( GetCloudConfigs $getCloudConfigs, @@ -21,8 +21,8 @@ public function __construct( public function create( string $name, string $namespace, - $description = "" - ) { + string $description = "" + ) :bool { if ($this->getCloudConfigs->haveCloudConfigInNamespace($name, $namespace)) { throw new \Exception("Have a cloud config with this name in this namespace", 1); } diff --git a/src/classes/Tools/CloudConfig/DeployConfigToContainer.php b/src/classes/Tools/CloudConfig/DeployConfigToContainer.php index bdd8b7f4..7578f5a3 100644 --- a/src/classes/Tools/CloudConfig/DeployConfigToContainer.php +++ b/src/classes/Tools/CloudConfig/DeployConfigToContainer.php @@ -11,10 +11,10 @@ class DeployConfigToContainer { - private $deployToProfile; - private $createInstance; - private $getConfig; - + private DeployToProfile $deployToProfile; + private CreateInstance $createInstance; + private GetConfig $getConfig; + public function __construct( DeployToProfile $deployToProfile, CreateInstance $createInstance, @@ -44,7 +44,7 @@ public function deploy( } } - if (!is_numeric($cloudConfigRevId)) { + if (is_numeric($cloudConfigId) && !is_numeric($cloudConfigRevId)) { $imageDetails = $this->getConfig->getLatestConfig($cloudConfigId)["imageDetails"]; } else { $imageDetails = $this->getConfig->getLatestConfigByRevId($cloudConfigRevId)["imageDetails"]; diff --git a/src/classes/Tools/CloudConfig/DeployToProfile.php b/src/classes/Tools/CloudConfig/DeployToProfile.php index 40046b93..041a77e9 100644 --- a/src/classes/Tools/CloudConfig/DeployToProfile.php +++ b/src/classes/Tools/CloudConfig/DeployToProfile.php @@ -7,8 +7,8 @@ class DeployToProfile { - private $getConfig; - + private GetConfig $getConfig; + public function __construct(GetConfig $getConfig) { $this->getConfig = $getConfig; diff --git a/src/classes/Tools/CloudConfig/GetDetails.php b/src/classes/Tools/CloudConfig/GetDetails.php index ff436c9e..cc1ca80e 100644 --- a/src/classes/Tools/CloudConfig/GetDetails.php +++ b/src/classes/Tools/CloudConfig/GetDetails.php @@ -7,9 +7,9 @@ class GetDetails { - private $getConfig; - private $getLatest; - + private GetConfig $getConfig; + private GetLatest $getLatest; + public function __construct(GetConfig $getConfig, GetLatest $getLatest) { $this->getConfig = $getConfig; diff --git a/src/classes/Tools/CloudConfig/Update.php b/src/classes/Tools/CloudConfig/Update.php index 66a60ef9..c459b4e4 100644 --- a/src/classes/Tools/CloudConfig/Update.php +++ b/src/classes/Tools/CloudConfig/Update.php @@ -6,8 +6,8 @@ class Update { - private $updateModel; - + private UpdateModel $updateModel; + public function __construct(UpdateModel $updateModel) { $this->updateModel = $updateModel; diff --git a/src/classes/Tools/Clusters/GetAllClusters.php b/src/classes/Tools/Clusters/GetAllClusters.php index bc84886e..5cbfa95b 100644 --- a/src/classes/Tools/Clusters/GetAllClusters.php +++ b/src/classes/Tools/Clusters/GetAllClusters.php @@ -3,33 +3,29 @@ namespace dhope0000\LXDClient\Tools\Clusters; use dhope0000\LXDClient\Model\Hosts\HostList; -use dhope0000\LXDClient\Model\Hosts\GetDetails; use dhope0000\LXDClient\Tools\Hosts\GetResources; use dhope0000\LXDClient\Constants\LxdRecursionLevels; class GetAllClusters { - private $hostList; - private $getDetails; - private $getResources; + private HostList $hostList; + private GetResources $getResources; public function __construct( HostList $hostList, - GetDetails $getDetails, GetResources $getResources ) { $this->hostList = $hostList; - $this->getDetails = $getDetails; $this->getResources = $getResources; } - public function get() + public function get() :array { $clusters = $this->createClusterGroupsWithInfo(); return $this->calculateClusterStats($clusters); } - public function convertHostsToClusters($hosts, $addResources = false) + public function convertHostsToClusters($hosts, bool $addResources = false) :array { $hostByUrl = []; foreach ($hosts as $host) { @@ -79,13 +75,13 @@ public function convertHostsToClusters($hosts, $addResources = false) return $clusters; } - private function createClusterGroupsWithInfo() + private function createClusterGroupsWithInfo() :array { $hosts = $this->hostList->getOnlineHostsWithDetails(); return $this->convertHostsToClusters($hosts, true); } - private function calculateClusterStats(array $clusters) + private function calculateClusterStats(array $clusters) :array { foreach ($clusters as $index => $cluster) { $totalMemory = 0; diff --git a/src/classes/Tools/Clusters/GetCluster.php b/src/classes/Tools/Clusters/GetCluster.php index f606e04f..e2add913 100644 --- a/src/classes/Tools/Clusters/GetCluster.php +++ b/src/classes/Tools/Clusters/GetCluster.php @@ -6,7 +6,7 @@ class GetCluster { - private $getAllClusters; + private GetAllClusters $getAllClusters; public function __construct(GetAllClusters $getAllClusters) { diff --git a/src/classes/Tools/Dashboard/GetDashboard.php b/src/classes/Tools/Dashboard/GetDashboard.php index 85e05c21..02272620 100644 --- a/src/classes/Tools/Dashboard/GetDashboard.php +++ b/src/classes/Tools/Dashboard/GetDashboard.php @@ -7,9 +7,9 @@ class GetDashboard { - private $fetchUserDashboards; - private $getGraphableProjectAnalytics; - + private FetchUserDashboards $fetchUserDashboards; + private GetGraphableProjectAnalytics $getGraphableProjectAnalytics; + public function __construct( FetchUserDashboards $fetchUserDashboards, GetGraphableProjectAnalytics $getGraphableProjectAnalytics diff --git a/src/classes/Tools/Deployments/Authorise/AuthoriseDeploymentAccess.php b/src/classes/Tools/Deployments/Authorise/AuthoriseDeploymentAccess.php index 4257c489..cc6d2961 100644 --- a/src/classes/Tools/Deployments/Authorise/AuthoriseDeploymentAccess.php +++ b/src/classes/Tools/Deployments/Authorise/AuthoriseDeploymentAccess.php @@ -6,8 +6,8 @@ class AuthoriseDeploymentAccess { - private $fetchDeploymentProjectsUsers; - + private FetchDeploymentProjectsUsers $fetchDeploymentProjectsUsers; + public function __construct( FetchDeploymentProjectsUsers $fetchDeploymentProjectsUsers ) { diff --git a/src/classes/Tools/Deployments/ChangeDeploymentState.php b/src/classes/Tools/Deployments/ChangeDeploymentState.php index c7a8aaa6..c8a113f3 100644 --- a/src/classes/Tools/Deployments/ChangeDeploymentState.php +++ b/src/classes/Tools/Deployments/ChangeDeploymentState.php @@ -10,11 +10,11 @@ class ChangeDeploymentState { - private $authoriseDeploymentAccess; - private $hostHaveDeploymentProfiles; - private $getContainersInDeployment; - private $setStartTimes; - + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private HostHaveDeploymentProfiles $hostHaveDeploymentProfiles; + private GetContainersInDeployment $getContainersInDeployment; + private SetStartTimes $setStartTimes; + public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, HostHaveDeploymentProfiles $hostHaveDeploymentProfiles, diff --git a/src/classes/Tools/Deployments/Containers/GetContainersInDeployment.php b/src/classes/Tools/Deployments/Containers/GetContainersInDeployment.php index 48906541..b03b8a4a 100644 --- a/src/classes/Tools/Deployments/Containers/GetContainersInDeployment.php +++ b/src/classes/Tools/Deployments/Containers/GetContainersInDeployment.php @@ -6,8 +6,8 @@ class GetContainersInDeployment { - private $getConfig; - + private GetConfig $getConfig; + public function __construct(GetConfig $getConfig) { $this->getConfig = $getConfig; diff --git a/src/classes/Tools/Deployments/Containers/GetContainersInformation.php b/src/classes/Tools/Deployments/Containers/GetContainersInformation.php index ebb31e61..ca8cc349 100644 --- a/src/classes/Tools/Deployments/Containers/GetContainersInformation.php +++ b/src/classes/Tools/Deployments/Containers/GetContainersInformation.php @@ -6,8 +6,8 @@ class GetContainersInformation { - private $getDeployedContainers; - + private GetDeployedContainers $getDeployedContainers; + public function __construct(GetDeployedContainers $getDeployedContainers) { $this->getDeployedContainers = $getDeployedContainers; diff --git a/src/classes/Tools/Deployments/Containers/SetStartTimes.php b/src/classes/Tools/Deployments/Containers/SetStartTimes.php index cf6461e7..3801903d 100644 --- a/src/classes/Tools/Deployments/Containers/SetStartTimes.php +++ b/src/classes/Tools/Deployments/Containers/SetStartTimes.php @@ -6,8 +6,8 @@ class SetStartTimes { - private $updateStartTimes; - + private UpdateStartTimes $updateStartTimes; + public function __construct(UpdateStartTimes $updateStartTimes) { $this->updateStartTimes = $updateStartTimes; diff --git a/src/classes/Tools/Deployments/Containers/StoreDeployedContainerNames.php b/src/classes/Tools/Deployments/Containers/StoreDeployedContainerNames.php index 2e21bf7e..07a5c09a 100644 --- a/src/classes/Tools/Deployments/Containers/StoreDeployedContainerNames.php +++ b/src/classes/Tools/Deployments/Containers/StoreDeployedContainerNames.php @@ -6,8 +6,8 @@ class StoreDeployedContainerNames { - private $insertDeploymentContainer; - + private InsertDeploymentContainer $insertDeploymentContainer; + public function __construct(InsertDeploymentContainer $insertDeploymentContainer) { $this->insertDeploymentContainer = $insertDeploymentContainer; diff --git a/src/classes/Tools/Deployments/CreateDeployment.php b/src/classes/Tools/Deployments/CreateDeployment.php index 5c0dec44..560c672f 100644 --- a/src/classes/Tools/Deployments/CreateDeployment.php +++ b/src/classes/Tools/Deployments/CreateDeployment.php @@ -8,10 +8,10 @@ class CreateDeployment { - private $insertDeployment; - private $getConfig; - private $addCloudConfig; - + private InsertDeployment $insertDeployment; + private GetConfig $getConfig; + private AddCloudConfig $addCloudConfig; + public function __construct( InsertDeployment $insertDeployment, GetConfig $getConfig, diff --git a/src/classes/Tools/Deployments/DeleteDeployment.php b/src/classes/Tools/Deployments/DeleteDeployment.php index 2a75b540..a4078940 100644 --- a/src/classes/Tools/Deployments/DeleteDeployment.php +++ b/src/classes/Tools/Deployments/DeleteDeployment.php @@ -9,11 +9,11 @@ class DeleteDeployment { - private $authoriseDeploymentAccess; - private $hostHaveDeploymentProfiles; - private $getContainersInDeployment; - private $removeDeployment; - + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private HostHaveDeploymentProfiles $hostHaveDeploymentProfiles; + private GetContainersInDeployment $getContainersInDeployment; + private RemoveDeployment $removeDeployment; + public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, HostHaveDeploymentProfiles $hostHaveDeploymentProfiles, diff --git a/src/classes/Tools/Deployments/Deploy.php b/src/classes/Tools/Deployments/Deploy.php index cb7c8ecf..ebf2deb6 100644 --- a/src/classes/Tools/Deployments/Deploy.php +++ b/src/classes/Tools/Deployments/Deploy.php @@ -16,13 +16,13 @@ class Deploy { - private $authoriseDeploymentAccess; - private $deployToProfile; - private $hostHaveDeploymentProfiles; - private $createInstance; - private $getConfig; - private $storeDeployedContainerNames; - private $getDetails; + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private DeployToProfile $deployToProfile; + private HostHaveDeploymentProfiles $hostHaveDeploymentProfiles; + private CreateInstance $createInstance; + private GetConfig $getConfig; + private StoreDeployedContainerNames $storeDeployedContainerNames; + private GetDetails $getDetails; public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, @@ -42,7 +42,7 @@ public function __construct( $this->getDetails = $getDetails; } - public function deploy(int $userId, int $deploymentId, array $instances) + public function deploy(int $userId, int $deploymentId, array $instances) :array { $this->authoriseDeploymentAccess->authorise($userId, $deploymentId); $this->validateInstances($instances); @@ -106,7 +106,7 @@ public function deploy(int $userId, int $deploymentId, array $instances) ]; } - private function deployProfile(HostsCollection $hostCollection, int $deploymentId, int $revId) + private function deployProfile(HostsCollection $hostCollection, int $deploymentId, int $revId) :string { $profileName = StringTools::random(12); $this->deployToProfile->deployToHosts( @@ -122,7 +122,7 @@ private function deployProfile(HostsCollection $hostCollection, int $deploymentI return $profileName; } - public function getImageDetails($revIds) + public function getImageDetails($revIds) :array { $imageDetails = []; foreach ($revIds as $revId) { @@ -135,7 +135,7 @@ public function getImageDetails($revIds) return $imageDetails; } - private function generateInstanceName() + private function generateInstanceName() :string { try { $name = StringTools::random(12); @@ -148,7 +148,7 @@ private function generateInstanceName() } } - public function validateInstances(array $instances) + public function validateInstances(array $instances) :bool { foreach ($instances as $instance) { if (!isset($instance["revId"]) || !is_numeric($instance["revId"])) { diff --git a/src/classes/Tools/Deployments/GetCloudConfigs.php b/src/classes/Tools/Deployments/GetCloudConfigs.php index 0b033b72..bff0fed3 100644 --- a/src/classes/Tools/Deployments/GetCloudConfigs.php +++ b/src/classes/Tools/Deployments/GetCloudConfigs.php @@ -7,9 +7,9 @@ class GetCloudConfigs { - private $authoriseDeploymentAccess; - private $fetchCloudConfigs; - + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private FetchCloudConfigs $fetchCloudConfigs; + public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, FetchCloudConfigs $fetchCloudConfigs diff --git a/src/classes/Tools/Deployments/GetDeployment.php b/src/classes/Tools/Deployments/GetDeployment.php index dbd57a25..afec73f5 100644 --- a/src/classes/Tools/Deployments/GetDeployment.php +++ b/src/classes/Tools/Deployments/GetDeployment.php @@ -12,14 +12,14 @@ class GetDeployment { - private $authoriseDeploymentAccess; - private $fetchCloudConfigs; - private $hostHaveDeploymentProfiles; - private $getContainersInDeployment; - private $fetchDeployments; - private $getContainersInformation; - private $fetchDeploymentProjects; - + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private FetchCloudConfigs $fetchCloudConfigs; + private HostHaveDeploymentProfiles $hostHaveDeploymentProfiles; + private GetContainersInDeployment $getContainersInDeployment; + private FetchDeployments $fetchDeployments; + private GetContainersInformation $getContainersInformation; + private FetchDeploymentProjects $fetchDeploymentProjects; + public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, FetchCloudConfigs $fetchCloudConfigs, diff --git a/src/classes/Tools/Deployments/GetDeployments.php b/src/classes/Tools/Deployments/GetDeployments.php index 4fb508ab..7eeec15f 100644 --- a/src/classes/Tools/Deployments/GetDeployments.php +++ b/src/classes/Tools/Deployments/GetDeployments.php @@ -8,10 +8,10 @@ class GetDeployments { - private $fetchDeployments; - private $getDeployment; - private $fetchUserDetails; - + private FetchDeployments $fetchDeployments; + private GetDeployment $getDeployment; + private FetchUserDetails $fetchUserDetails; + public function __construct( FetchDeployments $fetchDeployments, GetDeployment $getDeployment, @@ -22,7 +22,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function getAll(int $userId) + public function getAll(int $userId) :array { $deploymentList = []; @@ -35,7 +35,7 @@ public function getAll(int $userId) return $this->addDetails($userId, $deploymentList); } - private function addDetails($userId, $deploymentList) + private function addDetails(int $userId, array $deploymentList) :array { foreach ($deploymentList as $index =>$deployment) { $details = $this->getDeployment->get($userId, $deployment["id"]); @@ -45,7 +45,7 @@ private function addDetails($userId, $deploymentList) return $deploymentList; } - private function getContainerDetails($containerDetails) + private function getContainerDetails(array $containerDetails) :array { $totalMem = 0; $totalContainers = 0; diff --git a/src/classes/Tools/Deployments/Profiles/HostHaveDeploymentProfiles.php b/src/classes/Tools/Deployments/Profiles/HostHaveDeploymentProfiles.php index 51679ae4..a8f23162 100644 --- a/src/classes/Tools/Deployments/Profiles/HostHaveDeploymentProfiles.php +++ b/src/classes/Tools/Deployments/Profiles/HostHaveDeploymentProfiles.php @@ -7,8 +7,8 @@ class HostHaveDeploymentProfiles { - private $getAllProfiles; - + private GetAllProfiles $getAllProfiles; + public function __construct(GetAllProfiles $getAllProfiles) { $this->getAllProfiles = $getAllProfiles; diff --git a/src/classes/Tools/Deployments/Projects/SetDeploymentProjects.php b/src/classes/Tools/Deployments/Projects/SetDeploymentProjects.php index 8e7c5da2..4e74f541 100644 --- a/src/classes/Tools/Deployments/Projects/SetDeploymentProjects.php +++ b/src/classes/Tools/Deployments/Projects/SetDeploymentProjects.php @@ -10,11 +10,11 @@ class SetDeploymentProjects { - private $authoriseDeploymentAccess; - private $validatePermissions; - private $fetchDeploymentProjects; - private $insertDeploymentProject; - private $deleteDeploymentProject; + private AuthoriseDeploymentAccess $authoriseDeploymentAccess; + private ValidatePermissions $validatePermissions; + private FetchDeploymentProjects $fetchDeploymentProjects; + private InsertDeploymentProject $insertDeploymentProject; + private DeleteDeploymentProject $deleteDeploymentProject; public function __construct( AuthoriseDeploymentAccess $authoriseDeploymentAccess, diff --git a/src/classes/Tools/Hosts/AddHosts.php b/src/classes/Tools/Hosts/AddHosts.php index 446a2cce..92590d0d 100644 --- a/src/classes/Tools/Hosts/AddHosts.php +++ b/src/classes/Tools/Hosts/AddHosts.php @@ -10,12 +10,12 @@ class AddHosts { - private $generateCert; - private $addHost; - private $getDetails; - private $lxdClient; - private $fetchUserDetails; - + private GenerateCert $generateCert; + private AddHostModel $addHost; + private GetDetails $getDetails; + private LxdClient $lxdClient; + private FetchUserDetails $fetchUserDetails; + public function __construct( AddHostModel $addHost, GenerateCert $generateCert, @@ -30,7 +30,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function add($userId, array $hostsDetails) + public function add(int $userId, array $hostsDetails) :bool { $isAdmin = $this->fetchUserDetails->isAdmin($userId) === "1"; @@ -117,10 +117,14 @@ public function add($userId, array $hostsDetails) return true; } - private function addSchemeAndDefaultPort($name) + private function addSchemeAndDefaultPort(string $name) { $parts = parse_url($name); + if ($parts == false) { + throw new \Exception("Couldn't parse '$name'", 1); + } + if (!isset($parts["scheme"])) { $parts["scheme"] = "https://"; } elseif ($parts["scheme"] == "https") { @@ -136,7 +140,7 @@ private function addSchemeAndDefaultPort($name) return $parts["scheme"] . $path . ":" . $parts["port"]; } - private function validateDetails($host) + private function validateDetails(array $host) { if (isset($host["socketPath"]) && !empty($host["socketPath"])) { if (!isset($host["alias"]) || empty($host["alias"])) { diff --git a/src/classes/Tools/Hosts/Certificates/GetHostCertificate.php b/src/classes/Tools/Hosts/Certificates/GetHostCertificate.php index 7302df4f..33baf1eb 100644 --- a/src/classes/Tools/Hosts/Certificates/GetHostCertificate.php +++ b/src/classes/Tools/Hosts/Certificates/GetHostCertificate.php @@ -4,7 +4,7 @@ class GetHostCertificate { - public static function get(string $hostWithPort) + public static function get(string $hostWithPort) :array { $g = stream_context_create(array("ssl" => array( "capture_peer_cert" => true, @@ -22,6 +22,10 @@ public static function get(string $hostWithPort) $g ); + if ($r == false) { + throw new \Exception("Couldn't connect to host: {$hostWithPort}", 1); + } + $cont = stream_context_get_params($r); $cert = $cont["options"]["ssl"]["peer_certificate"]; diff --git a/src/classes/Tools/Hosts/Certificates/RenewCert.php b/src/classes/Tools/Hosts/Certificates/RenewCert.php index 678676f3..eeb1d110 100644 --- a/src/classes/Tools/Hosts/Certificates/RenewCert.php +++ b/src/classes/Tools/Hosts/Certificates/RenewCert.php @@ -7,9 +7,9 @@ class RenewCert { - private $updateHost; + private UpdateHost $updateHost; - private $certSettings = [ + private array $certSettings = [ "countryName" => "UK", "stateOrProvinceName" => "London", "localityName" => "London", @@ -24,7 +24,7 @@ public function __construct(UpdateHost $updateHost) $this->updateHost = $updateHost; } - public function renew(Host $host) + public function renew(Host $host) :bool { $certificate = $this->generateCert(); @@ -42,13 +42,20 @@ public function renew(Host $host) return true; } - private function generateCert() + private function generateCert() :array { // Generate certificate $privkey = openssl_pkey_new(); $cert = openssl_csr_new($this->certSettings, $privkey); - $cert = openssl_csr_sign($cert, null, $privkey, 365); + if ($cert == false) { + throw new \Exception("Couldn't generate new certificate", 1); + } + + $cert = openssl_csr_sign($cert, null, $privkey, 365); + if ($cert == false) { + throw new \Exception("Couldn't sign new certificate", 1); + } // Generate strings openssl_x509_export($cert, $certString); openssl_pkey_export($privkey, $privkeyString); @@ -60,7 +67,7 @@ private function generateCert() ]; } - private function writeCert($host, $cert) + private function writeCert(Host $host, array $cert) :bool { if (file_put_contents($_ENV["LXD_CERTS_DIR"] . $host->getAlias() . ".key", $cert["key"]) != true) { throw new \Exception("Couldn't store key file", 1); diff --git a/src/classes/Tools/Hosts/GPU/GetAll.php b/src/classes/Tools/Hosts/GPU/GetAll.php index 0cdcea26..ee7f3c60 100644 --- a/src/classes/Tools/Hosts/GPU/GetAll.php +++ b/src/classes/Tools/Hosts/GPU/GetAll.php @@ -7,8 +7,8 @@ class GetAll { - private $getResources; - + private GetResources $getResources; + public function __construct(GetResources $getResources) { $this->getResources = $getResources; diff --git a/src/classes/Tools/Hosts/GenerateCert.php b/src/classes/Tools/Hosts/GenerateCert.php index c1e2d59e..4f276848 100644 --- a/src/classes/Tools/Hosts/GenerateCert.php +++ b/src/classes/Tools/Hosts/GenerateCert.php @@ -8,9 +8,9 @@ class GenerateCert { - private $lxdClient; - - private $certSettings = [ + private LxdClient $lxdClient; + + private array $certSettings = [ "countryName" => "UK", "stateOrProvinceName" => "Isle Of Wight", "localityName" => "Cowes", @@ -26,10 +26,10 @@ public function __construct(LxdClient $lxdClient) } public function createCertAndPushToServer( - $urlAndPort, - $trustPassword, - $socketPath - ) { + string $urlAndPort, + string $trustPassword, + ?string $socketPath = null + ) :array { $paths = $this->createCertKeyAndCombinedPaths($urlAndPort, $socketPath); $this->generateCert($paths); @@ -44,12 +44,19 @@ public function createCertAndPushToServer( ]; } - private function createCertKeyAndCombinedPaths($urlAndPort, $socketPath) + private function createCertKeyAndCombinedPaths(string $urlAndPort, ?string $socketPath) :array { if (!empty($socketPath)) { $host = $urlAndPort; } else { - $host = parse_url($urlAndPort)["host"]; + $host = parse_url($urlAndPort); + + if ($host == false) { + throw new \Exception("Couldn't parse '$urlAndPort'", 1); + } + + + $host = $host["host"]; } @@ -60,7 +67,7 @@ private function createCertKeyAndCombinedPaths($urlAndPort, $socketPath) ]; } - private function createShortPaths($pathsArray) + private function createShortPaths(array $pathsArray) :array { foreach ($pathsArray as $key => $path) { $pathsArray[$key] = str_replace($_ENV["LXD_CERTS_DIR"], "", $path); @@ -68,7 +75,7 @@ private function createShortPaths($pathsArray) return $pathsArray; } - private function addToServer($urlAndPort, $trustPassword, $pathToCert, $socketPath) + private function addToServer(string $urlAndPort, string $trustPassword, string $pathToCert, ?string $socketPath) { $config = $this->lxdClient->createConfigArray($pathToCert, $socketPath); $config["timeout"] = 2; @@ -76,13 +83,22 @@ private function addToServer($urlAndPort, $trustPassword, $pathToCert, $socketPa return $lxd->certificates->add(file_get_contents($pathToCert), $trustPassword); } - private function generateCert($paths) + private function generateCert(array $paths) :bool { // Generate certificate $privkey = openssl_pkey_new(); $cert = openssl_csr_new($this->certSettings, $privkey); + + if ($cert == false) { + throw new \Exception("Couldn't generate new certificate", 1); + } + $cert = openssl_csr_sign($cert, null, $privkey, 365); + if ($cert == false) { + throw new \Exception("Couldn't sign new certificate", 1); + } + // Generate strings openssl_x509_export($cert, $certString); openssl_pkey_export($privkey, $privkeyString); diff --git a/src/classes/Tools/Hosts/GetClustersAndStandaloneHosts.php b/src/classes/Tools/Hosts/GetClustersAndStandaloneHosts.php index f1189298..172c38fe 100644 --- a/src/classes/Tools/Hosts/GetClustersAndStandaloneHosts.php +++ b/src/classes/Tools/Hosts/GetClustersAndStandaloneHosts.php @@ -7,9 +7,9 @@ class GetClustersAndStandaloneHosts { - private $getAllClusters; - private $hostList; - + private GetAllClusters $getAllClusters; + private HostList $hostList; + public function __construct( GetAllClusters $getAllClusters, HostList $hostList diff --git a/src/classes/Tools/Hosts/GetHostOverview.php b/src/classes/Tools/Hosts/GetHostOverview.php index 0d704578..ba37c729 100644 --- a/src/classes/Tools/Hosts/GetHostOverview.php +++ b/src/classes/Tools/Hosts/GetHostOverview.php @@ -2,7 +2,6 @@ namespace dhope0000\LXDClient\Tools\Hosts; -use dhope0000\LXDClient\Tools\Instances\GetHostsInstances; use dhope0000\LXDClient\Tools\Hosts\GetResources; use dhope0000\LXDClient\Objects\Host; use dhope0000\LXDClient\Tools\Hosts\HasExtension; @@ -13,22 +12,19 @@ class GetHostOverview { - private $getHostsInstances; - private $getResources; - private $hasExtension; - private $fetchUserDetails; - private $fetchAllowedProjects; - private $getGraphableProjectAnalytics; - + private GetResources $getResources; + private HasExtension $hasExtension; + private FetchUserDetails $fetchUserDetails; + private FetchAllowedProjects $fetchAllowedProjects; + private GetGraphableProjectAnalytics $getGraphableProjectAnalytics; + public function __construct( - GetHostsInstances $getHostsInstances, GetResources $getResources, HasExtension $hasExtension, FetchUserDetails $fetchUserDetails, FetchAllowedProjects $fetchAllowedProjects, GetGraphableProjectAnalytics $getGraphableProjectAnalytics ) { - $this->getHostsInstances = $getHostsInstances; $this->getResources = $getResources; $this->hasExtension = $hasExtension; $this->fetchUserDetails = $fetchUserDetails; diff --git a/src/classes/Tools/Hosts/GetHostsOverview.php b/src/classes/Tools/Hosts/GetHostsOverview.php index aa04acb8..61c63e7c 100644 --- a/src/classes/Tools/Hosts/GetHostsOverview.php +++ b/src/classes/Tools/Hosts/GetHostsOverview.php @@ -7,8 +7,8 @@ class GetHostsOverview { - private $hostList; - private $getDetails; + private HostList $hostList; + private GetDetails $getDetails; public function __construct( HostList $hostList, @@ -31,8 +31,21 @@ public function get() if ($socketPath === null) { $cert = file_get_contents($_ENV["LXD_CERTS_DIR"] . $host->getCertPath()); + if ($cert == false) { + throw new \Exception("Couldn't find cert at path {$host->getCertPath()}", 1); + } + $certinfo = openssl_x509_parse($cert); + + if ($certinfo == false) { + throw new \Exception("Couldn't parse cert at path {$host->getCertPath()}", 1); + } + $certExpires = \DateTime::createFromFormat('U', $certinfo["validTo_time_t"]); + + if ($certExpires == false) { + throw new \Exception("Couldn't extract valid date from {$host->getCertPath()}", 1); + } } $host->setCustomProp("certExpires", $certExpires->format("Y-m-d H:i:s")); } diff --git a/src/classes/Tools/Hosts/GetResources.php b/src/classes/Tools/Hosts/GetResources.php index 4ddd7be3..ecc63c81 100755 --- a/src/classes/Tools/Hosts/GetResources.php +++ b/src/classes/Tools/Hosts/GetResources.php @@ -6,14 +6,14 @@ class GetResources { - private $hasExtension; - + private HasExtension $hasExtension; + public function __construct(HasExtension $hasExtension) { $this->hasExtension = $hasExtension; } - public function getHostExtended(Host $host) + public function getHostExtended(Host $host) :array { $details = $host->resources->info(); diff --git a/src/classes/Tools/Hosts/HasExtension.php b/src/classes/Tools/Hosts/HasExtension.php index 60e0a5bf..6c938145 100644 --- a/src/classes/Tools/Hosts/HasExtension.php +++ b/src/classes/Tools/Hosts/HasExtension.php @@ -2,14 +2,13 @@ namespace dhope0000\LXDClient\Tools\Hosts; -use Opensaucesystems\Lxd\Client; use dhope0000\LXDClient\Objects\Host; class HasExtension { - private $hostCache = []; + private array $hostCache = []; - public function checkWithHost(Host $host, $extension) + public function checkWithHost(Host $host, string $extension) :bool { $hostUrl = $host->getUrl(); $info = isset($this->hostCache[$hostUrl]) ? $this->hostCache[$hostUrl] : $host->host->info(); diff --git a/src/classes/Tools/Hosts/Images/HostHasImage.php b/src/classes/Tools/Hosts/Images/HostHasImage.php index 99568975..f813e453 100644 --- a/src/classes/Tools/Hosts/Images/HostHasImage.php +++ b/src/classes/Tools/Hosts/Images/HostHasImage.php @@ -6,7 +6,7 @@ class HostHasImage { - public function has(Host $host, $fingerPrint) + public function has(Host $host, string $fingerPrint) { //NOTE The end point throws a 404 exception so we have to catch (sigh) try { diff --git a/src/classes/Tools/Hosts/Images/ImportImageIfNotHave.php b/src/classes/Tools/Hosts/Images/ImportImageIfNotHave.php index 1b6e704f..606f45e5 100644 --- a/src/classes/Tools/Hosts/Images/ImportImageIfNotHave.php +++ b/src/classes/Tools/Hosts/Images/ImportImageIfNotHave.php @@ -7,8 +7,8 @@ class ImportImageIfNotHave { - private $hostHasImage; - + private HostHasImage $hostHasImage; + public function __construct(HostHasImage $hostHasImage) { $this->hostHasImage = $hostHasImage; diff --git a/src/classes/Tools/Hosts/Instances/GetAllProxyDevices.php b/src/classes/Tools/Hosts/Instances/GetAllProxyDevices.php index ea9c7017..66fb7715 100644 --- a/src/classes/Tools/Hosts/Instances/GetAllProxyDevices.php +++ b/src/classes/Tools/Hosts/Instances/GetAllProxyDevices.php @@ -8,14 +8,14 @@ class GetAllProxyDevices { - private $getAllInstanceProxies; + private GetAllInstanceProxies $getAllInstanceProxies; public function __construct(GetAllInstanceProxies $getAllInstanceProxies) { $this->getAllInstanceProxies = $getAllInstanceProxies; } - public function get(Host $host) + public function get(Host $host) :array { // Recursion target? $instances = $host->instances->all(LxdRecursionLevels::INSTANCE_FULL_RECURSION); diff --git a/src/classes/Tools/Hosts/Instances/HostsHaveInstance.php b/src/classes/Tools/Hosts/Instances/HostsHaveInstance.php index 9151abd3..c9ac73ac 100755 --- a/src/classes/Tools/Hosts/Instances/HostsHaveInstance.php +++ b/src/classes/Tools/Hosts/Instances/HostsHaveInstance.php @@ -6,7 +6,7 @@ class HostsHaveInstance { - public function ifHostInListHasContainerNameThrow(HostsCollection $hosts, string $name) + public function ifHostInListHasContainerNameThrow(HostsCollection $hosts, string $name) :bool { foreach ($hosts as $host) { $allContainers = $host->instances->all(); diff --git a/src/classes/Tools/Hosts/RemoveHost.php b/src/classes/Tools/Hosts/RemoveHost.php index 7bab0eb8..e0d5d733 100644 --- a/src/classes/Tools/Hosts/RemoveHost.php +++ b/src/classes/Tools/Hosts/RemoveHost.php @@ -15,16 +15,16 @@ class RemoveHost { - private $deleteHost; - private $fetchUserDetails; - private $deleteDeploymentInstances; - private $deleteBackup; - private $deleteBackupSchedules; - private $deleteMetrics; - private $deleteAnalytics; - private $deleteUserAccess; - private $deleteUserProject; - + private DeleteHost $deleteHost; + private FetchUserDetails $fetchUserDetails; + private DeleteDeploymentInstances $deleteDeploymentInstances; + private DeleteBackup $deleteBackup; + private DeleteBackupSchedules $deleteBackupSchedules; + private DeleteMetrics $deleteMetrics; + private DeleteAnalytics $deleteAnalytics; + private DeleteUserAccess $deleteUserAccess; + private DeleteUserProject $deleteUserProject; + public function __construct( DeleteHost $deleteHost, FetchUserDetails $fetchUserDetails, @@ -47,7 +47,7 @@ public function __construct( $this->deleteUserProject = $deleteUserProject; } - public function remove($userId, int $hostId) + public function remove($userId, int $hostId) :void { $isAdmin = $this->fetchUserDetails->isAdmin($userId) === "1"; diff --git a/src/classes/Tools/Hosts/Settings/UpdateHostSettings.php b/src/classes/Tools/Hosts/Settings/UpdateHostSettings.php index 25efcd44..8732fff1 100644 --- a/src/classes/Tools/Hosts/Settings/UpdateHostSettings.php +++ b/src/classes/Tools/Hosts/Settings/UpdateHostSettings.php @@ -8,10 +8,10 @@ class UpdateHostSettings { - private $setHostSettings; - private $haveAlias; - private $fetchUserDetails; - + private SetHostSettings $setHostSettings; + private HaveAlias $haveAlias; + private FetchUserDetails $fetchUserDetails; + public function __construct( SetHostSettings $setHostSettings, HaveAlias $haveAlias, diff --git a/src/classes/Tools/Hosts/Warnings/AckWarning.php b/src/classes/Tools/Hosts/Warnings/AckWarning.php index 64afbf9c..7e47ab9d 100644 --- a/src/classes/Tools/Hosts/Warnings/AckWarning.php +++ b/src/classes/Tools/Hosts/Warnings/AckWarning.php @@ -7,14 +7,14 @@ class AckWarning { - private $validatePermissions; - + private ValidatePermissions $validatePermissions; + public function __construct(ValidatePermissions $validatePermissions) { $this->validatePermissions = $validatePermissions; } - public function ack(int $userId, Host $host, string $id) + public function ack(int $userId, Host $host, string $id) :void { $this->validatePermissions->isAdminOrThrow($userId); $host->warnings->status->acknowledge($id); diff --git a/src/classes/Tools/Hosts/Warnings/DeleteWarning.php b/src/classes/Tools/Hosts/Warnings/DeleteWarning.php index 808ad354..ada25a5f 100644 --- a/src/classes/Tools/Hosts/Warnings/DeleteWarning.php +++ b/src/classes/Tools/Hosts/Warnings/DeleteWarning.php @@ -7,14 +7,14 @@ class DeleteWarning { - private $validatePermissions; - + private ValidatePermissions $validatePermissions; + public function __construct(ValidatePermissions $validatePermissions) { $this->validatePermissions = $validatePermissions; } - public function delete(int $userId, Host $host, string $id) + public function delete(int $userId, Host $host, string $id) :void { $this->validatePermissions->isAdminOrThrow($userId); $host->warnings->remove($id); diff --git a/src/classes/Tools/Images/DeleteImages.php b/src/classes/Tools/Images/DeleteImages.php index 7c9a10c7..a74d5b4e 100755 --- a/src/classes/Tools/Images/DeleteImages.php +++ b/src/classes/Tools/Images/DeleteImages.php @@ -7,10 +7,10 @@ class DeleteImages { - private $getDetails; - private $fetchAllowedProjects; - private $fetchUserDetails; - + private GetDetails $getDetails; + private FetchAllowedProjects $fetchAllowedProjects; + private FetchUserDetails $fetchUserDetails; + public function __construct( GetDetails $getDetails, FetchAllowedProjects $fetchAllowedProjects, @@ -21,7 +21,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function delete(int $userId, array $imageData) + public function delete(int $userId, array $imageData) :array { $output = []; $hostCache = []; diff --git a/src/classes/Tools/Images/GetAllImages.php b/src/classes/Tools/Images/GetAllImages.php index 03b06a55..f0eb0e3b 100755 --- a/src/classes/Tools/Images/GetAllImages.php +++ b/src/classes/Tools/Images/GetAllImages.php @@ -6,8 +6,8 @@ class GetAllImages { - private $universe; - + private Universe $universe; + public function __construct(Universe $universe) { $this->universe = $universe; @@ -45,7 +45,7 @@ private function getImages(Host $host) } usort($details, function ($a, $b) { - return $a["properties"]["description"] > $b["properties"]["description"]; + return $a["properties"]["description"] > $b["properties"]["description"] ? 1 : -1; }); return $details; diff --git a/src/classes/Tools/Images/GetImageProperties.php b/src/classes/Tools/Images/GetImageProperties.php index e350b944..4cb487df 100644 --- a/src/classes/Tools/Images/GetImageProperties.php +++ b/src/classes/Tools/Images/GetImageProperties.php @@ -5,7 +5,7 @@ class GetImageProperties { - private $supportedProprties = [ + private array $supportedProprties = [ "public"=>"", "auto_update"=>"" ]; @@ -15,7 +15,7 @@ public function getAll(Host $host, string $fingerprint) return $host->images->info($fingerprint); } - public function getFiltertedList(Host $host, string $fingerprint) + public function getFiltertedList(Host $host, string $fingerprint) :array { $info = $this->getAll($host, $fingerprint); return array_intersect_key($info, $this->supportedProprties); diff --git a/src/classes/Tools/Images/ImportRemoteImagesByFingerprint.php b/src/classes/Tools/Images/ImportRemoteImagesByFingerprint.php index f25d74f2..483f97ce 100644 --- a/src/classes/Tools/Images/ImportRemoteImagesByFingerprint.php +++ b/src/classes/Tools/Images/ImportRemoteImagesByFingerprint.php @@ -6,7 +6,7 @@ class ImportRemoteImagesByFingerprint { - public function import(HostsCollection $hosts, array $images, $urlKey) + public function import(HostsCollection $hosts, array $images, string $urlKey) :array { $urlMap = [ "linuxcontainers"=>'https://images.linuxcontainers.org', diff --git a/src/classes/Tools/Images/SearchRemoteImages.php b/src/classes/Tools/Images/SearchRemoteImages.php index a65a1e34..7a104020 100755 --- a/src/classes/Tools/Images/SearchRemoteImages.php +++ b/src/classes/Tools/Images/SearchRemoteImages.php @@ -4,8 +4,11 @@ class SearchRemoteImages { - public function get($urlKey = "linuxcontainers", $searchType = "container", $searchArch = "amd64") - { + public function get( + string $urlKey = "linuxcontainers", + string $searchType = "container", + string $searchArch = "amd64" + ) :array { $urlMap = [ "linuxcontainers"=>'https://images.linuxcontainers.org/streams/v1/images.json', "ubuntu-release"=>'https://cloud-images.ubuntu.com/releases/streams/v1/com.ubuntu.cloud:released:download.json', @@ -95,7 +98,7 @@ public function get($urlKey = "linuxcontainers", $searchType = "container", $sea return $output; } - private function parseUbuntuSimpleStream($product) + private function parseUbuntuSimpleStream($product) :array { return [ "imOs"=>$product["os"], @@ -105,7 +108,7 @@ private function parseUbuntuSimpleStream($product) ]; } - private function parseLinuxContainersSimpleStream($name, $product) + private function parseLinuxContainersSimpleStream($name, $product) :array { $nameParts = explode(":", $name); return [ @@ -116,7 +119,7 @@ private function parseLinuxContainersSimpleStream($name, $product) ]; } - public function getSimpleStreamsJson($url) + public function getSimpleStreamsJson($url) :array { // Get cURL resource $curl = curl_init(); @@ -132,6 +135,10 @@ public function getSimpleStreamsJson($url) // Close request to clear up some resources curl_close($curl); + if (!is_string($resp)) { + throw new \Exception("Incorrect response from image server ", 1); + } + return json_decode($resp, true); } } diff --git a/src/classes/Tools/Images/UpdateImageProperties.php b/src/classes/Tools/Images/UpdateImageProperties.php index 2c6df0cb..4b3b7430 100644 --- a/src/classes/Tools/Images/UpdateImageProperties.php +++ b/src/classes/Tools/Images/UpdateImageProperties.php @@ -6,7 +6,7 @@ class UpdateImageProperties { - private $supportedProprties = [ + private array $supportedProprties = [ "public"=>"", "auto_update"=>"" ]; diff --git a/src/classes/Tools/InstanceSettings/FirstRun.php b/src/classes/Tools/InstanceSettings/FirstRun.php index 1ab6d2e5..ea3f561e 100644 --- a/src/classes/Tools/InstanceSettings/FirstRun.php +++ b/src/classes/Tools/InstanceSettings/FirstRun.php @@ -9,12 +9,12 @@ class FirstRun { - private $fetchUserDetails; - private $addHosts; - private $resetPassword; - private $insertSetting; + private FetchUserDetails $fetchUserDetails; + private AddHosts $addHosts; + private ResetPassword $resetPassword; + private InsertSetting $insertSetting; - private $adminUserId = 1; + private int $adminUserId = 1; public function __construct( FetchUserDetails $fetchUserDetails, @@ -28,7 +28,7 @@ public function __construct( $this->insertSetting = $insertSetting; } - public function run(array $hosts, string $adminPassword, array $settings = []) + public function run(array $hosts, string $adminPassword, array $settings = []) :void { if ($this->fetchUserDetails->adminPasswordBlank() !== true) { throw new \Exception("Cant run first run", 1); diff --git a/src/classes/Tools/InstanceSettings/GetSettingsOverview.php b/src/classes/Tools/InstanceSettings/GetSettingsOverview.php index 378fea22..ccf20ecb 100644 --- a/src/classes/Tools/InstanceSettings/GetSettingsOverview.php +++ b/src/classes/Tools/InstanceSettings/GetSettingsOverview.php @@ -6,8 +6,8 @@ class GetSettingsOverview { - private $fetchTokens; - + private FetchTokens $fetchTokens; + public function __construct(FetchTokens $fetchTokens) { $this->fetchTokens = $fetchTokens; diff --git a/src/classes/Tools/InstanceSettings/Ldap/SaveLdapSettings.php b/src/classes/Tools/InstanceSettings/Ldap/SaveLdapSettings.php index 178b120f..04df00cf 100644 --- a/src/classes/Tools/InstanceSettings/Ldap/SaveLdapSettings.php +++ b/src/classes/Tools/InstanceSettings/Ldap/SaveLdapSettings.php @@ -9,9 +9,9 @@ class SaveLdapSettings { - private $validatePermissions; - private $insertSetting; - private $ldap; + private ValidatePermissions $validatePermissions; + private InsertSetting $insertSetting; + private Ldap $ldap; public function __construct(ValidatePermissions $validatePermissions, InsertSetting $insertSetting, Ldap $ldap) { @@ -20,7 +20,7 @@ public function __construct(ValidatePermissions $validatePermissions, InsertSett $this->ldap = $ldap; } - public function save($userId, $settings) :bool + public function save(int $userId, array $settings) :bool { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/InstanceSettings/SaveSettings.php b/src/classes/Tools/InstanceSettings/SaveSettings.php index 9d117196..c3d99900 100644 --- a/src/classes/Tools/InstanceSettings/SaveSettings.php +++ b/src/classes/Tools/InstanceSettings/SaveSettings.php @@ -7,8 +7,8 @@ class SaveSettings { - private $insertSetting; - private $validatePermissions; + private InsertSetting $insertSetting; + private ValidatePermissions $validatePermissions; public function __construct(ValidatePermissions $validatePermissions, InsertSetting $insertSetting) { diff --git a/src/classes/Tools/Instances/Backups/AddBackupSchedule.php b/src/classes/Tools/Instances/Backups/AddBackupSchedule.php index da6810ea..08d92847 100644 --- a/src/classes/Tools/Instances/Backups/AddBackupSchedule.php +++ b/src/classes/Tools/Instances/Backups/AddBackupSchedule.php @@ -8,9 +8,9 @@ class AddBackupSchedule { - private $insertBackupSchedule; - private $updateBackupSchedules; - + private InsertBackupSchedule $insertBackupSchedule; + private UpdateBackupSchedules $updateBackupSchedules; + public function __construct( InsertBackupSchedule $insertBackupSchedule, UpdateBackupSchedules $updateBackupSchedules @@ -20,7 +20,7 @@ public function __construct( } public function add( - string $userId, + int $userId, Host $host, string $instance, string $frequency, diff --git a/src/classes/Tools/Instances/Backups/BackupInstance.php b/src/classes/Tools/Instances/Backups/BackupInstance.php index 63b67d17..e04b3fd7 100644 --- a/src/classes/Tools/Instances/Backups/BackupInstance.php +++ b/src/classes/Tools/Instances/Backups/BackupInstance.php @@ -9,9 +9,9 @@ class BackupInstance { - private $storeBackupLocally; + private StoreBackupLocally $storeBackupLocally; - private $hasExtension; + private HasExtension $hasExtension; public function __construct( StoreBackupLocally $storeBackupLocally, diff --git a/src/classes/Tools/Instances/Backups/DeleteLocalBackup.php b/src/classes/Tools/Instances/Backups/DeleteLocalBackup.php index d0a959d1..fa360458 100644 --- a/src/classes/Tools/Instances/Backups/DeleteLocalBackup.php +++ b/src/classes/Tools/Instances/Backups/DeleteLocalBackup.php @@ -8,9 +8,9 @@ class DeleteLocalBackup { - private $fetchBackup; - private $deleteBackup; - private $validatePermissions; + private FetchBackup $fetchBackup; + private DeleteBackup $deleteBackup; + private ValidatePermissions $validatePermissions; public function __construct( FetchBackup $fetchBackup, diff --git a/src/classes/Tools/Instances/Backups/DeleteRemoteBackup.php b/src/classes/Tools/Instances/Backups/DeleteRemoteBackup.php index b45567f5..65653ca0 100644 --- a/src/classes/Tools/Instances/Backups/DeleteRemoteBackup.php +++ b/src/classes/Tools/Instances/Backups/DeleteRemoteBackup.php @@ -8,7 +8,7 @@ class DeleteRemoteBackup { - private $hasExtension; + private HasExtension $hasExtension; public function __construct(HasExtension $hasExtension) { @@ -24,6 +24,6 @@ public function delete(Host $host, string $instance, string $backup) throw new \Exception("Host doesn't support backups", 1); } - return $host->instances->backups->remove($instance, $backup, [], true); + return $host->instances->backups->remove($instance, $backup, true); } } diff --git a/src/classes/Tools/Instances/Backups/DownloadFile.php b/src/classes/Tools/Instances/Backups/DownloadFile.php index 0b1f0730..7f629885 100644 --- a/src/classes/Tools/Instances/Backups/DownloadFile.php +++ b/src/classes/Tools/Instances/Backups/DownloadFile.php @@ -9,9 +9,9 @@ class DownloadFile { - private $lxdClient; - private $getDetails; - + private LxdClient $lxdClient; + private GetDetails $getDetails; + public function __construct(LxdClient $lxdClient, GetDetails $getDetails) { $this->lxdClient = $lxdClient; diff --git a/src/classes/Tools/Instances/Backups/GetInstanceBackups.php b/src/classes/Tools/Instances/Backups/GetInstanceBackups.php index 950adbcc..8c55ec4c 100644 --- a/src/classes/Tools/Instances/Backups/GetInstanceBackups.php +++ b/src/classes/Tools/Instances/Backups/GetInstanceBackups.php @@ -9,8 +9,8 @@ class GetInstanceBackups { - private $fetchInstanceBackups; - private $hasExtension; + private FetchInstanceBackups $fetchInstanceBackups; + private HasExtension $hasExtension; public function __construct( FetchInstanceBackups $fetchInstanceBackups, @@ -20,7 +20,7 @@ public function __construct( $this->hasExtension = $hasExtension; } - public function get(Host $host, string $instance) + public function get(Host $host, string $instance) :array { if ($this->hasExtension->checkWithHost($host, LxdApiExtensions::CONTAINER_BACKUP) !== true) { throw new \Exception("Host doesn't support backups", 1); @@ -37,7 +37,7 @@ public function get(Host $host, string $instance) ]; } - private function addFileSizeToLocal(array &$localBackups) + private function addFileSizeToLocal(array &$localBackups) :void { foreach ($localBackups as $index => $backup) { $fileSize = $backup["fileszie"]; @@ -48,7 +48,7 @@ private function addFileSizeToLocal(array &$localBackups) } } - private function getRemoteBackups($host, string $instance, array $localBackups) + private function getRemoteBackups($host, string $instance, array $localBackups) :array { $backups = $host->instances->backups->all($instance); @@ -66,7 +66,7 @@ private function getRemoteBackups($host, string $instance, array $localBackups) return $backups; } - private function backupDownloadedLocally($localBackups, string $name, $created) + private function backupDownloadedLocally($localBackups, string $name, $created) :bool { foreach ($localBackups as $backup) { if ($backup["backupName"] == $name && new \DateTime($created) == new \DateTime($backup["dateCreated"])) { diff --git a/src/classes/Tools/Instances/Backups/StoreBackupLocally.php b/src/classes/Tools/Instances/Backups/StoreBackupLocally.php index b73cf9dd..4d426328 100644 --- a/src/classes/Tools/Instances/Backups/StoreBackupLocally.php +++ b/src/classes/Tools/Instances/Backups/StoreBackupLocally.php @@ -18,12 +18,12 @@ class StoreBackupLocally { - private $getSetting; - private $filesystem; - private $insertInstanceBackup; - private $deleteRemoteBackup; - private $hasExtension; - private $downloadFile; + private GetSetting $getSetting; + private Filesystem $filesystem; + private InsertInstanceBackup $insertInstanceBackup; + private DeleteRemoteBackup $deleteRemoteBackup; + private HasExtension $hasExtension; + private DownloadFile $downloadFile; public function __construct( GetSetting $getSetting, diff --git a/src/classes/Tools/Instances/Comments/SetInstanceComment.php b/src/classes/Tools/Instances/Comments/SetInstanceComment.php index 241db496..217afa68 100644 --- a/src/classes/Tools/Instances/Comments/SetInstanceComment.php +++ b/src/classes/Tools/Instances/Comments/SetInstanceComment.php @@ -5,7 +5,7 @@ class SetInstanceComment { - public function set(Host $host, string $instanceName, string $comment) + public function set(Host $host, string $instanceName, string $comment) :bool { $instance = $host->instances->info($instanceName); @@ -16,7 +16,7 @@ public function set(Host $host, string $instanceName, string $comment) } $host->instances->replace($instanceName, $instance); - + return true; } } diff --git a/src/classes/Tools/Instances/Copy.php b/src/classes/Tools/Instances/Copy.php index 3eb3fa47..1d8d1366 100755 --- a/src/classes/Tools/Instances/Copy.php +++ b/src/classes/Tools/Instances/Copy.php @@ -6,8 +6,8 @@ class Copy { - private $migrate; - + private Migrate $migrate; + public function __construct(Migrate $migrate) { $this->migrate = $migrate; @@ -20,7 +20,7 @@ public function copy( Host $destination, string $targetProject = "", bool $copyProfiles = false - ) { + ) :array { if ($host->getHostId() !== $destination->getHostId()) { return $this->migrate->migrate( $host, diff --git a/src/classes/Tools/Instances/CreateInstance.php b/src/classes/Tools/Instances/CreateInstance.php index f61ec264..61ea0e7c 100644 --- a/src/classes/Tools/Instances/CreateInstance.php +++ b/src/classes/Tools/Instances/CreateInstance.php @@ -9,9 +9,9 @@ class CreateInstance { - private $hostsHaveInstance; - private $importImageIfNotHave; - private $fetchInstanceType; + private HostsHaveInstance $hostsHaveInstance; + private ImportImageIfNotHave $importImageIfNotHave; + private FetchInstanceType $fetchInstanceType; public function __construct( HostsHaveInstance $hostsHaveInstance, @@ -83,11 +83,11 @@ public function create( private function createOptionsArray( - $type, - $profiles, - $imageDetails, - $server = "", - $instanceType = "", + string $type, + array $profiles, + array $imageDetails, + string $server = "", + string $instanceType = "", array $gpus = null, array $config = [] ) { diff --git a/src/classes/Tools/Instances/DeleteInstance.php b/src/classes/Tools/Instances/DeleteInstance.php index 265a30f2..a6158bb6 100755 --- a/src/classes/Tools/Instances/DeleteInstance.php +++ b/src/classes/Tools/Instances/DeleteInstance.php @@ -6,8 +6,8 @@ class DeleteInstance { - private $updateBackupSchedules; - + private UpdateBackupSchedules $updateBackupSchedules; + public function __construct(UpdateBackupSchedules $updateBackupSchedules) { $this->updateBackupSchedules = $updateBackupSchedules; diff --git a/src/classes/Tools/Instances/DeleteInstances.php b/src/classes/Tools/Instances/DeleteInstances.php index ce011b4b..cba2efca 100644 --- a/src/classes/Tools/Instances/DeleteInstances.php +++ b/src/classes/Tools/Instances/DeleteInstances.php @@ -6,8 +6,8 @@ class DeleteInstances { - private $updateBackupSchedules; - + private UpdateBackupSchedules $updateBackupSchedules; + public function __construct(UpdateBackupSchedules $updateBackupSchedules) { $this->updateBackupSchedules = $updateBackupSchedules; diff --git a/src/classes/Tools/Instances/Devices/Proxy/AddProxyDevice.php b/src/classes/Tools/Instances/Devices/Proxy/AddProxyDevice.php index ca5b27ba..0227534b 100644 --- a/src/classes/Tools/Instances/Devices/Proxy/AddProxyDevice.php +++ b/src/classes/Tools/Instances/Devices/Proxy/AddProxyDevice.php @@ -12,7 +12,7 @@ public function add( string $proxyName, string $source, string $destination - ) { + ) :bool { $devices = [ $proxyName=>[ "listen"=>$source, diff --git a/src/classes/Tools/Instances/Devices/Proxy/DeleteProxyDevice.php b/src/classes/Tools/Instances/Devices/Proxy/DeleteProxyDevice.php index df04d8bd..37406452 100644 --- a/src/classes/Tools/Instances/Devices/Proxy/DeleteProxyDevice.php +++ b/src/classes/Tools/Instances/Devices/Proxy/DeleteProxyDevice.php @@ -10,7 +10,7 @@ public function delete( Host $host, string $instance, string $device - ) { + ) :bool { $info = $host->instances->info($instance); if (isset($info["devices"][$device]) && $info["devices"][$device]["type"] == "proxy") { diff --git a/src/classes/Tools/Instances/Devices/Proxy/GetAllInstanceProxies.php b/src/classes/Tools/Instances/Devices/Proxy/GetAllInstanceProxies.php index 82b69e9a..cb52dfe8 100644 --- a/src/classes/Tools/Instances/Devices/Proxy/GetAllInstanceProxies.php +++ b/src/classes/Tools/Instances/Devices/Proxy/GetAllInstanceProxies.php @@ -4,7 +4,7 @@ class GetAllInstanceProxies { - public function get(array $devices) + public function get(array $devices) :array { $output = []; foreach ($devices as $name => $device) { diff --git a/src/classes/Tools/Instances/Files/GetPath.php b/src/classes/Tools/Instances/Files/GetPath.php index 02d7782e..4ed3b392 100644 --- a/src/classes/Tools/Instances/Files/GetPath.php +++ b/src/classes/Tools/Instances/Files/GetPath.php @@ -9,7 +9,7 @@ class GetPath { private $cache; private $instanceUrlKey; - + public function __construct(ArrayAdapter $cache) { @@ -20,7 +20,7 @@ public function get( Host $host, string $instance, string $path, - string $download + int $download ) { $host->callClientMethod("addCache", $this->cache); diff --git a/src/classes/Tools/Instances/Files/UploadFiles.php b/src/classes/Tools/Instances/Files/UploadFiles.php index e03a6534..6a674512 100644 --- a/src/classes/Tools/Instances/Files/UploadFiles.php +++ b/src/classes/Tools/Instances/Files/UploadFiles.php @@ -6,10 +6,15 @@ class UploadFiles { - public function upload(Host $host, string $instance, string $path, array $files) + public function upload(Host $host, string $instance, string $path, array $files) :bool { foreach ($files as $file) { $content = file_get_contents($file['tmp_name']); + + if ($content == false) { + throw new \Exception("Couldn't process uploaded file", 1); + } + $localPath = $path . "/" . $file["name"]; $response = $host->instances->files->write($instance, $localPath, $content); } diff --git a/src/classes/Tools/Instances/GetHostsInstances.php b/src/classes/Tools/Instances/GetHostsInstances.php index 913bccf7..0ba045c3 100755 --- a/src/classes/Tools/Instances/GetHostsInstances.php +++ b/src/classes/Tools/Instances/GetHostsInstances.php @@ -9,9 +9,9 @@ class GetHostsInstances { - private $hostList; - private $hasExtension; - + private HostList $hostList; + private HasExtension $hasExtension; + public function __construct(HostList $hostList, HasExtension $hasExtension) { $this->hostList = $hostList; diff --git a/src/classes/Tools/Instances/GetInstance.php b/src/classes/Tools/Instances/GetInstance.php index 871bdcc0..9baf6575 100644 --- a/src/classes/Tools/Instances/GetInstance.php +++ b/src/classes/Tools/Instances/GetInstance.php @@ -11,10 +11,10 @@ class GetInstance { - private $fetchDeployments; - private $hasExtension; - private $fetchMetrics; - private $getAllInstanceProxies; + private FetchDeployments $fetchDeployments; + private HasExtension $hasExtension; + private FetchMetrics $fetchMetrics; + private GetAllInstanceProxies $getAllInstanceProxies; public function __construct( FetchDeployments $fetchDeployments, diff --git a/src/classes/Tools/Instances/GetInstanceSettings.php b/src/classes/Tools/Instances/GetInstanceSettings.php index 300caeed..35c9e22f 100644 --- a/src/classes/Tools/Instances/GetInstanceSettings.php +++ b/src/classes/Tools/Instances/GetInstanceSettings.php @@ -7,8 +7,8 @@ class GetInstanceSettings { - private $getSettings; - + private GetSettings $getSettings; + public function __construct(GetSettings $getSettings) { $this->getSettings = $getSettings; diff --git a/src/classes/Tools/Instances/InstanceTypes/AddInstanceType.php b/src/classes/Tools/Instances/InstanceTypes/AddInstanceType.php index 3ab9a92d..c4a06f0f 100644 --- a/src/classes/Tools/Instances/InstanceTypes/AddInstanceType.php +++ b/src/classes/Tools/Instances/InstanceTypes/AddInstanceType.php @@ -7,9 +7,9 @@ class AddInstanceType { - private $fetchInstanceType; - private $insertInstanceType; - + private FetchInstanceType $fetchInstanceType; + private InsertInstanceType $insertInstanceType; + public function __construct( FetchInstanceType $fetchInstanceType, InsertInstanceType $insertInstanceType @@ -18,7 +18,7 @@ public function __construct( $this->insertInstanceType = $insertInstanceType; } - public function add(int $userId, int $providerId, string $name, float $cpu, float $mem) + public function add(int $userId, int $providerId, string $name, float $cpu, float $mem) :void { if ($this->fetchInstanceType->fetchByName($name)) { throw new \Exception("Already have a instance with this name, they must be globally unique", 1); diff --git a/src/classes/Tools/Instances/InstanceTypes/GetInstanceTypes.php b/src/classes/Tools/Instances/InstanceTypes/GetInstanceTypes.php index 9ee9e3cb..bb78ffaa 100644 --- a/src/classes/Tools/Instances/InstanceTypes/GetInstanceTypes.php +++ b/src/classes/Tools/Instances/InstanceTypes/GetInstanceTypes.php @@ -6,14 +6,14 @@ class GetInstanceTypes { - private $fetchInstanceTypes; - + private FetchInstanceTypes $fetchInstanceTypes; + public function __construct(FetchInstanceTypes $fetchInstanceTypes) { $this->fetchInstanceTypes = $fetchInstanceTypes; } - public function getGroupedByProvider() + public function getGroupedByProvider() :array { $types = $this->fetchInstanceTypes->fetchAll(); $output = []; diff --git a/src/classes/Tools/Instances/InstanceTypes/Providers/AddProvider.php b/src/classes/Tools/Instances/InstanceTypes/Providers/AddProvider.php index 226f7832..e93a7596 100644 --- a/src/classes/Tools/Instances/InstanceTypes/Providers/AddProvider.php +++ b/src/classes/Tools/Instances/InstanceTypes/Providers/AddProvider.php @@ -6,7 +6,7 @@ class AddProvider { - private $insertProvider; + private InsertProvider $insertProvider; public function __construct( InsertProvider $insertProvider @@ -14,7 +14,7 @@ public function __construct( $this->insertProvider = $insertProvider; } - public function add(int $userId, string $name) + public function add(int $userId, string $name) :void { $this->insertProvider->insert($name); } diff --git a/src/classes/Tools/Instances/InstanceTypes/Providers/RemoveProvider.php b/src/classes/Tools/Instances/InstanceTypes/Providers/RemoveProvider.php index 212aaa31..e4bafc33 100644 --- a/src/classes/Tools/Instances/InstanceTypes/Providers/RemoveProvider.php +++ b/src/classes/Tools/Instances/InstanceTypes/Providers/RemoveProvider.php @@ -7,8 +7,8 @@ class RemoveProvider { - private $deleteTypes; - private $deleteProvider; + private DeleteTypes $deleteTypes; + private DeleteProvider $deleteProvider; public function __construct( DeleteTypes $deleteTypes, @@ -18,7 +18,7 @@ public function __construct( $this->deleteProvider = $deleteProvider; } - public function remove(int $providerId) + public function remove(int $providerId) :void { //NOTE Setting the FK to cascade would be nice, but ive made terrible // design descisions. diff --git a/src/classes/Tools/Instances/Metrics/DisablePullGathering.php b/src/classes/Tools/Instances/Metrics/DisablePullGathering.php index 80e39de0..3d7b74c5 100644 --- a/src/classes/Tools/Instances/Metrics/DisablePullGathering.php +++ b/src/classes/Tools/Instances/Metrics/DisablePullGathering.php @@ -8,8 +8,8 @@ class DisablePullGathering { - private $deleteMetrics; - private $removeProfiles; + private DeleteMetrics $deleteMetrics; + private RemoveProfiles $removeProfiles; public function __construct(DeleteMetrics $deleteMetrics, RemoveProfiles $removeProfiles) { @@ -17,7 +17,7 @@ public function __construct(DeleteMetrics $deleteMetrics, RemoveProfiles $remove $this->removeProfiles = $removeProfiles; } - public function disable(Host $host, string $instance, bool $clearData = false) + public function disable(Host $host, string $instance, bool $clearData = false) :bool { if ($clearData) { $this->deleteMetrics->deleteForInstance($host->getHostId(), $instance, "default"); diff --git a/src/classes/Tools/Instances/Metrics/EnablePullGathering.php b/src/classes/Tools/Instances/Metrics/EnablePullGathering.php index 16ba8871..a8ed853c 100644 --- a/src/classes/Tools/Instances/Metrics/EnablePullGathering.php +++ b/src/classes/Tools/Instances/Metrics/EnablePullGathering.php @@ -8,9 +8,9 @@ class EnablePullGathering { - private $deployGenericPullProfile; - private $assignProfiles; - + private DeployGenericPullProfile $deployGenericPullProfile; + private AssignProfiles $assignProfiles; + public function __construct( DeployGenericPullProfile $deployGenericPullProfile, AssignProfiles $assignProfiles diff --git a/src/classes/Tools/Instances/Metrics/GetAvailableHostsMetrics.php b/src/classes/Tools/Instances/Metrics/GetAvailableHostsMetrics.php index c427b6c7..9f6a4a59 100644 --- a/src/classes/Tools/Instances/Metrics/GetAvailableHostsMetrics.php +++ b/src/classes/Tools/Instances/Metrics/GetAvailableHostsMetrics.php @@ -6,14 +6,14 @@ class GetAvailableHostsMetrics { - private $fetchMetrics; - + private FetchMetrics $fetchMetrics; + public function __construct(FetchMetrics $fetchMetrics) { $this->fetchMetrics = $fetchMetrics; } - public function get() + public function get() :array { $hosts = $this->fetchMetrics->fetchAvailableMetricsByHost(); $output = array_fill_keys(array_keys($hosts), ["instances"=>[]]); diff --git a/src/classes/Tools/Instances/Metrics/GetHostContainerStatus.php b/src/classes/Tools/Instances/Metrics/GetHostContainerStatus.php index d60222bb..1e9e6c65 100644 --- a/src/classes/Tools/Instances/Metrics/GetHostContainerStatus.php +++ b/src/classes/Tools/Instances/Metrics/GetHostContainerStatus.php @@ -7,14 +7,14 @@ class GetHostContainerStatus { - private $getAllProfiles; - + private GetAllProfiles $getAllProfiles; + public function __construct(GetAllProfiles $getAllProfiles) { $this->getAllProfiles = $getAllProfiles; } - public function get() + public function get() :array { $allProfiles = $this->getAllProfiles->getAllProfiles(true); diff --git a/src/classes/Tools/Instances/Metrics/GetMetricsForContainer.php b/src/classes/Tools/Instances/Metrics/GetMetricsForContainer.php index bdc61b39..609d893a 100644 --- a/src/classes/Tools/Instances/Metrics/GetMetricsForContainer.php +++ b/src/classes/Tools/Instances/Metrics/GetMetricsForContainer.php @@ -8,9 +8,9 @@ class GetMetricsForContainer { - private $fetchMetrics; - private $fetchType; - private $dateTools; + private FetchMetrics $fetchMetrics; + private FetchType $fetchType; + private DateTools $dateTools; public function __construct(FetchMetrics $fetchMetrics, FetchType $fetchType, DateTools $dateTools) { @@ -19,12 +19,12 @@ public function __construct(FetchMetrics $fetchMetrics, FetchType $fetchType, Da $this->dateTools = $dateTools; } - public function getAllTypes($hostId, $container) + public function getAllTypes(int $hostId, string $container) :array { return $this->fetchMetrics->fetchAllTypes($hostId, $container); } - public function getTypeFilters($hostId, $container, $type) + public function getTypeFilters(int $hostId, string $container, int $type) :array { $startDate = (new \DateTime)->modify("-6 months"); $allMetrics = $this->fetchMetrics->fetchByHostContainerType($hostId, $container, $type, $startDate); @@ -42,7 +42,7 @@ public function getTypeFilters($hostId, $container, $type) return array_values($keys); } - public function get($hostId, $container, $type, $filter, $range = "P30I") + public function get(int $hostId, string $container, int $type, string $filter, string $range = "P30I") :array { $startDate = (new \DateTime())->modify($range); diff --git a/src/classes/Tools/Instances/Metrics/GetUserDashboard.php b/src/classes/Tools/Instances/Metrics/GetUserDashboard.php index 25f02a22..9a84aa3e 100644 --- a/src/classes/Tools/Instances/Metrics/GetUserDashboard.php +++ b/src/classes/Tools/Instances/Metrics/GetUserDashboard.php @@ -8,10 +8,10 @@ class GetUserDashboard { - private $fetchUserDashboards; - private $fetchDashboardGraphs; - private $getMetricsForContainer; - + private FetchUserDashboards $fetchUserDashboards; + private FetchDashboardGraphs $fetchDashboardGraphs; + private GetMetricsForContainer $getMetricsForContainer; + public function __construct( FetchUserDashboards $fetchUserDashboards, FetchDashboardGraphs $fetchDashboardGraphs, diff --git a/src/classes/Tools/Instances/Metrics/ImportHostInsanceMetrics.php b/src/classes/Tools/Instances/Metrics/ImportHostInsanceMetrics.php index 1018cfb2..af57b589 100644 --- a/src/classes/Tools/Instances/Metrics/ImportHostInsanceMetrics.php +++ b/src/classes/Tools/Instances/Metrics/ImportHostInsanceMetrics.php @@ -1,4 +1,4 @@ -insertMetric = $insertMetric; } - public function import(Host $host, array $instancesToScan) + public function import(Host $host, array $instancesToScan) :void { //TODO Should probably check that the host supports this extension // but how old is that host (Wish the LXD docs were clearer)? @@ -60,7 +60,7 @@ public function import(Host $host, array $instancesToScan) } } - private function addInstanceNvidiaGpuUsage($host, $instance, $state) + private function addInstanceNvidiaGpuUsage(Host $host, string $instance, array $state) :bool { $command = "nvidia-smi --query-gpu=name,gpu_uuid,temperature.gpu,utilization.gpu,utilization.memory,memory.total,memory.free,memory.used --format=csv"; $lxdResponse = $host->instances->execute($instance, $command, $record = true, [], true); @@ -80,7 +80,7 @@ private function addInstanceNvidiaGpuUsage($host, $instance, $state) $csv = array_map('str_getcsv', $output); $gpuDetails = []; foreach ($csv as $gpu) { - $gpu = array_map("trim", $gpu); + $gpu = array_map('trim', $gpu); $gpuDetails["{$gpu[0]} temperature (Id: {$gpu[1]}"] = $gpu[2]; $gpuDetails["{$gpu[0]} utilization % (Id: {$gpu[1]}"] = explode(" ", $gpu[3])[0]; $gpuDetails["{$gpu[0]} memory utilization % (Id: {$gpu[1]}"] = explode(" ", $gpu[4])[0]; @@ -96,9 +96,10 @@ private function addInstanceNvidiaGpuUsage($host, $instance, $state) $instance, [$metricKey=>$gpuDetails] ); + return true; } - private function addInstanceLoadAverage($host, $instance) + private function addInstanceLoadAverage(Host $host, string $instance) :bool { $output = $host->instances->execute($instance, "cat /proc/loadavg", $record = true, [], true); @@ -109,7 +110,7 @@ private function addInstanceLoadAverage($host, $instance) $x = explode(" ", $averages); $dateTime = (new \DateTimeImmutable())->format("Y-m-d H:i:s"); - $matched = $this->matchTypeAndStore($dateTime, $host, $instance, [ + $this->matchTypeAndStore($dateTime, $host, $instance, [ "loadAvg"=>[ "1 minute"=>$x[0], "5 minutes"=>$x[1], @@ -119,7 +120,7 @@ private function addInstanceLoadAverage($host, $instance) return true; } - private function addInstanceStorageUsage($host, $instance, $instanceState) + private function addInstanceStorageUsage(Host $host, string $instance, array $instanceState) :void { $metricKey = "storageUsage"; @@ -138,7 +139,7 @@ private function addInstanceStorageUsage($host, $instance, $instanceState) [$metricKey=>$storageDetails] ); } - private function addInstanceNetworkUsage($host, $instance, $instanceState) + private function addInstanceNetworkUsage(Host $host, string $instance, array $instanceState) :void { $metricKey = "networkUsage"; @@ -160,7 +161,7 @@ private function addInstanceNetworkUsage($host, $instance, $instanceState) ); } - private function addInstanceMemoryUsage($host, $instance, $instanceState) + private function addInstanceMemoryUsage(Host $host, string $instance, array $instanceState) :void { $key = "memoryUsage"; @@ -172,9 +173,8 @@ private function addInstanceMemoryUsage($host, $instance, $instanceState) ); } - private function matchTypeAndStore($date, $host, $container, $content) + private function matchTypeAndStore(string $date, Host $host, string $container, array $content) :void { - $output = []; foreach ($content as $key=>$value) { if (!isset($this->keyCache[$key])) { $this->keyCache[$key] = $this->fetchType->fetchIdByTemplateKey($key); @@ -190,6 +190,5 @@ private function matchTypeAndStore($date, $host, $container, $content) json_encode($value) ); } - return $output; } } diff --git a/src/classes/Tools/Instances/Metrics/RemoveInstanceMetricHistory.php b/src/classes/Tools/Instances/Metrics/RemoveInstanceMetricHistory.php index 27d3b40e..7759373b 100644 --- a/src/classes/Tools/Instances/Metrics/RemoveInstanceMetricHistory.php +++ b/src/classes/Tools/Instances/Metrics/RemoveInstanceMetricHistory.php @@ -8,8 +8,8 @@ class RemoveInstanceMetricHistory { - private $getSetting; - private $deleteMetrics; + private GetSetting $getSetting; + private DeleteMetrics $deleteMetrics; public function __construct( GetSetting $getSetting, @@ -19,7 +19,7 @@ public function __construct( $this->deleteMetrics = $deleteMetrics; } - public function remove() + public function remove() :void { $howFarBack = $this->getSetting->getSettingLatestValue(InstanceSettingsKeys::INSTANCE_METRIC_HISTORY); $before = (new \DateTime())->modify($howFarBack); diff --git a/src/classes/Tools/Instances/Metrics/RemoveMetrics.php b/src/classes/Tools/Instances/Metrics/RemoveMetrics.php index 954daa2e..21a00de8 100755 --- a/src/classes/Tools/Instances/Metrics/RemoveMetrics.php +++ b/src/classes/Tools/Instances/Metrics/RemoveMetrics.php @@ -8,9 +8,9 @@ class RemoveMetrics { - private $fetchMetrics; - private $insertMetric; - private $deleteMetrics; + private FetchMetrics $fetchMetrics; + private InsertMetric $insertMetric; + private DeleteMetrics $deleteMetrics; public function __construct( FetchMetrics $fetchMetrics, @@ -22,17 +22,15 @@ public function __construct( $this->deleteMetrics = $deleteMetrics; } - public function remove() + public function remove() :void { $olderThan = new \DateTime("-1 day"); $olderThan->setTime( - $olderThan->format('H'), - $olderThan->format('i'), + (int) $olderThan->format('H'), + (int) $olderThan->format('i'), 00 ); - - $metrics = $this->fetchMetrics->fetchGroupedByFiveMinutes($olderThan); $groupedByHost = $this->groupMetrics($metrics); $result = $this->averageGrouped($groupedByHost); @@ -44,7 +42,7 @@ public function remove() $this->insertMetrics($result["toInsert"]); } - public function insertMetrics(array $toInsert) + public function insertMetrics(array $toInsert) :void { foreach ($toInsert as $metric) { $this->insertMetric->insert( @@ -57,7 +55,7 @@ public function insertMetrics(array $toInsert) } } - public function groupMetrics($metrics) + public function groupMetrics(array $metrics) :array { $groupedByHost = []; foreach ($metrics as $metric) { @@ -91,7 +89,7 @@ public function groupMetrics($metrics) return $groupedByHost; } - public function averageGrouped(array $groupedByHost) + public function averageGrouped(array $groupedByHost) :array { $idsToDelete = []; $toInsert = []; diff --git a/src/classes/Tools/Instances/Migrate.php b/src/classes/Tools/Instances/Migrate.php index 596e1f6e..8443ae7b 100755 --- a/src/classes/Tools/Instances/Migrate.php +++ b/src/classes/Tools/Instances/Migrate.php @@ -44,7 +44,18 @@ public function checkIfMigratingToSameHost(Host $source, Host $destination) private function checkIfHostUrlIsLocalhost(Host $host, string $type) { - if (parse_url($host->getUrl())["host"] == "localhost") { + if ($host->getSocketPath()) { + throw new \Exception("{$host->getAlias()} uses socket, cant migrate", 1); + } + + $urlParts = parse_url($host->getUrl()); + + if ($urlParts == false) { + throw new \Exception("Couldn't parse host url {$host->getUrl()}", 1); + } + + + if ($urlParts["host"] == "localhost") { throw new \Exception("Your $type server has a URL of 'localhost', this wont work!", 1); } } diff --git a/src/classes/Tools/Instances/RecordedActions/GetAllInstanceRecordedActions.php b/src/classes/Tools/Instances/RecordedActions/GetAllInstanceRecordedActions.php index 6212234d..7ad2c81e 100644 --- a/src/classes/Tools/Instances/RecordedActions/GetAllInstanceRecordedActions.php +++ b/src/classes/Tools/Instances/RecordedActions/GetAllInstanceRecordedActions.php @@ -8,16 +8,16 @@ class GetAllInstanceRecordedActions { - private $fetchRecordedActions; - private $routeToNameMapping; - + private FetchRecordedActions $fetchRecordedActions; + private RouteToNameMapping $routeToNameMapping; + public function __construct(FetchRecordedActions $fetchRecordedActions, RouteToNameMapping $routeToNameMapping) { $this->fetchRecordedActions = $fetchRecordedActions; $this->routeToNameMapping = $routeToNameMapping; } - public function get(Host $host, string $instance) + public function get(Host $host, string $instance) :array { $logs = $this->fetchRecordedActions->fetchForHostInstance($host->getHostId(), $instance); $paramsToRemove = [ diff --git a/src/classes/Tools/Instances/Snapshot/GetSnapshotsOverview.php b/src/classes/Tools/Instances/Snapshot/GetSnapshotsOverview.php index 1d2d2ae9..751b5108 100644 --- a/src/classes/Tools/Instances/Snapshot/GetSnapshotsOverview.php +++ b/src/classes/Tools/Instances/Snapshot/GetSnapshotsOverview.php @@ -7,14 +7,14 @@ class GetSnapshotsOverview { - private $hasExtension; + private HasExtension $hasExtension; public function __construct(HasExtension $hasExtension) { $this->hasExtension = $hasExtension; } - public function get(Host $host, string $instance) + public function get(Host $host, string $instance) :array { $schedule = null; if ($this->hasExtension->checkWithHost($host, "snapshot_scheduling")) { diff --git a/src/classes/Tools/Instances/Snapshot/ScheduleSnapshots.php b/src/classes/Tools/Instances/Snapshot/ScheduleSnapshots.php index 76328d2d..9cbbdfca 100644 --- a/src/classes/Tools/Instances/Snapshot/ScheduleSnapshots.php +++ b/src/classes/Tools/Instances/Snapshot/ScheduleSnapshots.php @@ -7,7 +7,7 @@ class ScheduleSnapshots { - private $hasExtension; + private HasExtension $hasExtension; public function __construct(HasExtension $hasExtension) { @@ -21,7 +21,7 @@ public function schedule( string $pattern, string $expiry, int $snapshotStopped - ) { + ) :void { if (!$this->hasExtension->checkWithHost($host, "snapshot_scheduling")) { throw new \Exception("Host doesn't support scheduling", 1); } diff --git a/src/classes/Tools/Instances/VirtualMachines/CreateVirutalMachine.php b/src/classes/Tools/Instances/VirtualMachines/CreateVirutalMachine.php index 6ea9c7e1..a5d8ac77 100644 --- a/src/classes/Tools/Instances/VirtualMachines/CreateVirutalMachine.php +++ b/src/classes/Tools/Instances/VirtualMachines/CreateVirutalMachine.php @@ -8,8 +8,8 @@ class CreateVirutalMachine { - private $createInstance; - + private CreateInstance $createInstance; + public function __construct( CreateInstance $createInstance ) { @@ -23,7 +23,7 @@ public function create( array $imageDetails, bool $start, array $config = [] - ) { + ) :bool { $config["user.vendor-data"] = $this->getVendorData($username); $profileName = "VM-$username-" . (new \DateTime())->format("Y-m-d_H_i_s"); @@ -60,7 +60,7 @@ public function create( return true; } - private function getVendorData(string $username) + private function getVendorData(string $username) :string { return '#cloud-config users: diff --git a/src/classes/Tools/Instances/Volumes/AttachVolumes.php b/src/classes/Tools/Instances/Volumes/AttachVolumes.php index 2aa391ab..8c046965 100644 --- a/src/classes/Tools/Instances/Volumes/AttachVolumes.php +++ b/src/classes/Tools/Instances/Volumes/AttachVolumes.php @@ -6,7 +6,7 @@ class AttachVolumes { - private $validatePermissions; + private ValidatePermissions $validatePermissions; public function __construct(ValidatePermissions $validatePermissions) { @@ -20,7 +20,7 @@ public function attach( array $volume, string $name, string $path - ) { + ) :void { $this->validateVolume($volume); $this->validatePermissions->canAccessHostProjectOrThrow($userId, $host->getHostId(), $volume["project"]); @@ -36,7 +36,7 @@ public function attach( "type"=>"disk", "path"=>$path ]; - + $result = $host->instances->replace($container, $instanceConfig, true); if (isset($result["err"]) && $result["err"] !== "") { diff --git a/src/classes/Tools/Ldap/Ldap.php b/src/classes/Tools/Ldap/Ldap.php index 82924ab6..18c4514d 100644 --- a/src/classes/Tools/Ldap/Ldap.php +++ b/src/classes/Tools/Ldap/Ldap.php @@ -9,14 +9,14 @@ class Ldap { - private $getSetting; + private GetSetting $getSetting; public function __construct(GetSetting $getSetting) { $this->getSetting = $getSetting; } - public function getConnectionOrThrow($server) + public function getConnectionOrThrow(string $server) { $connection = ldap_connect($server); @@ -29,7 +29,7 @@ public function getConnectionOrThrow($server) return $connection; } - public function bindLdapOrThrow($con, $adminUser, $adminPass) + public function bindLdapOrThrow($con, string $adminUser, string $adminPass) { $ldapbind = @ldap_bind($con, $adminUser, $adminPass); if (!$ldapbind) { @@ -41,7 +41,7 @@ public function bindLdapOrThrow($con, $adminUser, $adminPass) /** * Returns username that can be looked up in the DB */ - public function verifyAccount($con, $username, $password) :string + public function verifyAccount($con, string $username, string $password) :string { $baseDn = $this->getSetting->getSettingLatestValue(InstanceSettingsKeys::LDAP_BASE_DN); $username = ldap_escape($username, "", LDAP_ESCAPE_FILTER); @@ -49,8 +49,14 @@ public function verifyAccount($con, $username, $password) :string $attrs = array("dn", "cn"); $search = ldap_search($con, $baseDn, $filter, $attrs); + + if ($search == false) { + throw new CantFindUserException($username); + } + $entries = ldap_get_entries($con, $search); - if ($entries["count"] == 0) { + + if ($entries == false || $entries["count"] == 0) { throw new CantFindUserException($username); } diff --git a/src/classes/Tools/Profiles/GetProfilesDashboard.php b/src/classes/Tools/Profiles/GetProfilesDashboard.php index 25b62b48..622f32af 100644 --- a/src/classes/Tools/Profiles/GetProfilesDashboard.php +++ b/src/classes/Tools/Profiles/GetProfilesDashboard.php @@ -8,7 +8,7 @@ class GetProfilesDashboard { private $universe; - + public function __construct(Universe $universe) { $this->universe = $universe; @@ -91,7 +91,7 @@ private function getProfilesAnalytics(array $profiles) :array return 0; } - return $aC < $bC; + return $aC < $bC ? 1 : -1; }); return $output; diff --git a/src/classes/Tools/ProjectAnalytics/GetGraphableProjectAnalytics.php b/src/classes/Tools/ProjectAnalytics/GetGraphableProjectAnalytics.php index dea90b31..88b94308 100644 --- a/src/classes/Tools/ProjectAnalytics/GetGraphableProjectAnalytics.php +++ b/src/classes/Tools/ProjectAnalytics/GetGraphableProjectAnalytics.php @@ -10,10 +10,10 @@ class GetGraphableProjectAnalytics { - private $fetchAnalytics; - private $fetchUserDetails; - private $fetchAllowedProjects; - private $dateTools; + private FetchAnalytics $fetchAnalytics; + private FetchUserDetails $fetchUserDetails; + private FetchAllowedProjects $fetchAllowedProjects; + private DateTools $dateTools; public function __construct( FetchAnalytics $fetchAnalytics, diff --git a/src/classes/Tools/ProjectAnalytics/RemoveProjectAnalyticData.php b/src/classes/Tools/ProjectAnalytics/RemoveProjectAnalyticData.php index cca81b5c..32f1dfc9 100644 --- a/src/classes/Tools/ProjectAnalytics/RemoveProjectAnalyticData.php +++ b/src/classes/Tools/ProjectAnalytics/RemoveProjectAnalyticData.php @@ -8,17 +8,14 @@ class RemoveProjectAnalyticData { - private $getSetting; - private $instanceSettingsKeys; - private $deleteAnalytics; + private GetSetting $getSetting; + private DeleteAnalytics $deleteAnalytics; public function __construct( GetSetting $getSetting, - InstanceSettingsKeys $instanceSettingsKeys, DeleteAnalytics $deleteAnalytics ) { $this->getSetting = $getSetting; - $this->instanceSettingsKeys = $instanceSettingsKeys; $this->deleteAnalytics = $deleteAnalytics; } diff --git a/src/classes/Tools/ProjectAnalytics/StoreProjectsOverview.php b/src/classes/Tools/ProjectAnalytics/StoreProjectsOverview.php index 97812caa..7c08c454 100644 --- a/src/classes/Tools/ProjectAnalytics/StoreProjectsOverview.php +++ b/src/classes/Tools/ProjectAnalytics/StoreProjectsOverview.php @@ -12,10 +12,10 @@ class StoreProjectsOverview { - private $fetchProjectAnalyticsTypes; - private $getProjectsOverview; - private $insertAnalytic; - private $fetchUsers; + private FetchProjectAnalyticsTypes $fetchProjectAnalyticsTypes; + private GetProjectsOverview $getProjectsOverview; + private InsertAnalytic $insertAnalytic; + private FetchUsers $fetchUsers; private $knownTypes = []; diff --git a/src/classes/Tools/Projects/CreateProject.php b/src/classes/Tools/Projects/CreateProject.php index 547438b2..c351533f 100644 --- a/src/classes/Tools/Projects/CreateProject.php +++ b/src/classes/Tools/Projects/CreateProject.php @@ -7,8 +7,8 @@ class CreateProject { - private $hasExtension; - + private HasExtension $hasExtension; + public function __construct(HasExtension $hasExtension) { $this->hasExtension = $hasExtension; @@ -19,7 +19,7 @@ public function create( string $name, string $description = "", array $config = [] - ) { + ) :bool { foreach ($hosts as $host) { //TODO Check if project exsits $supportsNetworks = $this->hasExtension->checkWithHost($host, "projects_networks"); diff --git a/src/classes/Tools/Projects/DeleteProject.php b/src/classes/Tools/Projects/DeleteProject.php index 1911da0c..b4fcd619 100644 --- a/src/classes/Tools/Projects/DeleteProject.php +++ b/src/classes/Tools/Projects/DeleteProject.php @@ -8,9 +8,9 @@ class DeleteProject { - private $deleteUserAccess; - private $deleteUserProject; - + private DeleteUserAccess $deleteUserAccess; + private DeleteUserProject $deleteUserProject; + public function __construct( DeleteUserAccess $deleteUserAccess, DeleteUserProject $deleteUserProject diff --git a/src/classes/Tools/Projects/GetHostProjectsOverview.php b/src/classes/Tools/Projects/GetHostProjectsOverview.php index ba9f67c9..00ab13e8 100644 --- a/src/classes/Tools/Projects/GetHostProjectsOverview.php +++ b/src/classes/Tools/Projects/GetHostProjectsOverview.php @@ -5,12 +5,13 @@ use dhope0000\LXDClient\Tools\User\ValidatePermissions; use dhope0000\LXDClient\Tools\Universe; use dhope0000\LXDClient\Model\Users\AllowedProjects\FetchAllowedProjects; +use dhope0000\LXDClient\Objects\Host; class GetHostProjectsOverview { - private $validatePermissions; - private $universe; - private $fetchAllowedProjects; + private ValidatePermissions $validatePermissions; + private Universe $universe; + private FetchAllowedProjects $fetchAllowedProjects; public function __construct(ValidatePermissions $validatePermissions, Universe $universe, FetchAllowedProjects $fetchAllowedProjects) { @@ -46,7 +47,7 @@ public function get(int $userId) return $x; } - private function addHostDetails($host, $groupedPermissions) + private function addHostDetails(Host $host, array $groupedPermissions) { $projects = $host->getCustomProp("projects"); @@ -64,7 +65,7 @@ private function addHostDetails($host, $groupedPermissions) $host->setCustomProp("projects", $out); } - private function groupAllowedPermissions($permissions) + private function groupAllowedPermissions(array $permissions) { $output = []; foreach ($permissions as $permission) { diff --git a/src/classes/Tools/Projects/GetHostsProjects.php b/src/classes/Tools/Projects/GetHostsProjects.php index dbbe5851..14f6e87e 100644 --- a/src/classes/Tools/Projects/GetHostsProjects.php +++ b/src/classes/Tools/Projects/GetHostsProjects.php @@ -6,14 +6,14 @@ class GetHostsProjects { - private $universe; - + private Universe $universe; + public function __construct(Universe $universe) { $this->universe = $universe; } - public function getAll($userId) + public function getAll(int $userId) :array { return $this->universe->getEntitiesUserHasAccesTo($userId, "projects"); } diff --git a/src/classes/Tools/Projects/GetProjectInfo.php b/src/classes/Tools/Projects/GetProjectInfo.php index 66f3f401..50a33338 100644 --- a/src/classes/Tools/Projects/GetProjectInfo.php +++ b/src/classes/Tools/Projects/GetProjectInfo.php @@ -8,14 +8,14 @@ class GetProjectInfo { - private $fetchAllowedProjects; - + private FetchAllowedProjects $fetchAllowedProjects; + public function __construct(FetchAllowedProjects $fetchAllowedProjects) { $this->fetchAllowedProjects = $fetchAllowedProjects; } - public function get(Host $host, string $projectName) + public function get(Host $host, string $projectName) :array { $project = $host->projects->info($projectName); $project["used_by"] = StringTools::usedByStringsToLinks( diff --git a/src/classes/Tools/Projects/GetProjectsOverview.php b/src/classes/Tools/Projects/GetProjectsOverview.php index 529018d2..251d10b1 100644 --- a/src/classes/Tools/Projects/GetProjectsOverview.php +++ b/src/classes/Tools/Projects/GetProjectsOverview.php @@ -4,12 +4,13 @@ use dhope0000\LXDClient\Tools\Universe; use dhope0000\LXDClient\Tools\Hosts\HasExtension; +use dhope0000\LXDClient\Objects\Host; class GetProjectsOverview { - private $universe; - private $hasExtension; - + private Universe $universe; + private HasExtension $hasExtension; + public function __construct(Universe $universe, HasExtension $hasExtension) { $this->universe = $universe; @@ -17,7 +18,7 @@ public function __construct(Universe $universe, HasExtension $hasExtension) } //Based on https://github.com/lxc/lxd/issues/7946#issuecomment-703367651 - public function get($userId) + public function get(int $userId) :array { $clustersAndStandalone = $this->universe->getEntitiesUserHasAccesTo($userId, "projects"); @@ -39,7 +40,7 @@ public function get($userId) return $clustersAndStandalone; } - private function calculateUsage(&$member) + private function calculateUsage(Host &$member) :void { if (!$member->hostOnline()) { return; @@ -106,7 +107,7 @@ private function calculateUsage(&$member) $member->setCustomProp("projects", $hostProjects); } - private function getLimitValues($config) + private function getLimitValues(array $config) :array { $expectedKeys = [ "limits.containers"=>["limit"=>null, "value"=>0], diff --git a/src/classes/Tools/Projects/Search/GetCommonToHostsProjects.php b/src/classes/Tools/Projects/Search/GetCommonToHostsProjects.php index 97da0ac0..d60aea08 100644 --- a/src/classes/Tools/Projects/Search/GetCommonToHostsProjects.php +++ b/src/classes/Tools/Projects/Search/GetCommonToHostsProjects.php @@ -8,8 +8,8 @@ class GetCommonToHostsProjects { - private $validatePermissions; - private $hasExtension; + private ValidatePermissions $validatePermissions; + private HasExtension $hasExtension; public function __construct(ValidatePermissions $validatePermissions, HasExtension $hasExtension) { @@ -17,7 +17,7 @@ public function __construct(ValidatePermissions $validatePermissions, HasExtensi $this->hasExtension = $hasExtension; } - public function get(int $userId, HostsCollection $hosts) + public function get(int $userId, HostsCollection $hosts) :array { $this->validatePermissions->isAdminOrThrow($userId); $projectsCount = []; diff --git a/src/classes/Tools/Projects/Users/GetUsersAccessToProject.php b/src/classes/Tools/Projects/Users/GetUsersAccessToProject.php index 1eaeddcb..aa9116c8 100644 --- a/src/classes/Tools/Projects/Users/GetUsersAccessToProject.php +++ b/src/classes/Tools/Projects/Users/GetUsersAccessToProject.php @@ -8,8 +8,8 @@ class GetUsersAccessToProject { - private $validatePermissions; - private $fetchAllowedProjects; + private ValidatePermissions $validatePermissions; + private FetchAllowedProjects $fetchAllowedProjects; public function __construct(ValidatePermissions $validatePermissions, FetchAllowedProjects $fetchAllowedProjects) { diff --git a/src/classes/Tools/Storage/CreateStoragePool.php b/src/classes/Tools/Storage/CreateStoragePool.php index 1ceeaa0c..88b62890 100644 --- a/src/classes/Tools/Storage/CreateStoragePool.php +++ b/src/classes/Tools/Storage/CreateStoragePool.php @@ -6,7 +6,7 @@ class CreateStoragePool { - public function create(HostsCollection $hosts, string $name, string $driver, array $config) + public function create(HostsCollection $hosts, string $name, string $driver, array $config) :bool { if ($driver === "dir" && isset($config["size"])) { unset($config["size"]); diff --git a/src/classes/Tools/Storage/GetStoragePool.php b/src/classes/Tools/Storage/GetStoragePool.php index 890f5404..51404caa 100644 --- a/src/classes/Tools/Storage/GetStoragePool.php +++ b/src/classes/Tools/Storage/GetStoragePool.php @@ -8,14 +8,14 @@ class GetStoragePool { - private $usedByFilter; + private UsedByFilter $usedByFilter; public function __construct(UsedByFilter $usedByFilter) { $this->usedByFilter = $usedByFilter; } - public function get(int $userId, Host $host, string $poolName) + public function get(int $userId, Host $host, string $poolName) :array { $info = $host->storage->info($poolName); @@ -33,6 +33,11 @@ public function get(int $userId, Host $host, string $poolName) foreach ($info["used_by"] as $i => $item) { if (strpos($item, '/1.0/storage-pools/') !== false) { $url = parse_url($item); + + if ($url == false) { + throw new \Exception("Couldn't parse '$item'", 1); + } + $project = "default"; if (isset($url["query"])) { parse_str($url["query"], $query); diff --git a/src/classes/Tools/Storage/GetUserStorage.php b/src/classes/Tools/Storage/GetUserStorage.php index c552b20e..06bbf317 100644 --- a/src/classes/Tools/Storage/GetUserStorage.php +++ b/src/classes/Tools/Storage/GetUserStorage.php @@ -7,15 +7,15 @@ class GetUserStorage { - private $universe; - + private Universe $universe; + public function __construct( Universe $universe ) { $this->universe = $universe; } - public function getAll($userId) + public function getAll(int $userId) :array { $clusters = $this->universe->getEntitiesUserHasAccesTo($userId, "pools"); @@ -50,7 +50,7 @@ public function getAll($userId) ]; } - private function calculateStats($stats, $pools) + private function calculateStats(array $stats, array $pools) :array { foreach ($pools as $pool) { $stats["storage"]["total"] += $pool["resources"]["space"]["total"]; @@ -62,7 +62,7 @@ private function calculateStats($stats, $pools) return $stats; } - private function getHostPools(Host $host) + private function getHostPools(Host $host) :array { if (!$host->hostOnline()) { return []; diff --git a/src/classes/Tools/Storage/Volumes/GetVolume.php b/src/classes/Tools/Storage/Volumes/GetVolume.php index da76a204..9ce3c6f6 100644 --- a/src/classes/Tools/Storage/Volumes/GetVolume.php +++ b/src/classes/Tools/Storage/Volumes/GetVolume.php @@ -9,9 +9,9 @@ class GetVolume { - private $validatePermissions; - private $usedByFilter; - + private ValidatePermissions $validatePermissions; + private UsedByFilter $usedByFilter; + public function __construct(ValidatePermissions $validatePermissions, UsedByFilter $usedByFilter) { $this->validatePermissions = $validatePermissions; diff --git a/src/classes/Tools/Storage/Volumes/GetVolumes.php b/src/classes/Tools/Storage/Volumes/GetVolumes.php index 96bce5e7..8b763a41 100644 --- a/src/classes/Tools/Storage/Volumes/GetVolumes.php +++ b/src/classes/Tools/Storage/Volumes/GetVolumes.php @@ -8,8 +8,8 @@ class GetVolumes { - private $usedByFilter; - + private UsedByFilter $usedByFilter; + public function __construct(UsedByFilter $usedByFilter) { $this->usedByFilter = $usedByFilter; @@ -26,6 +26,11 @@ public function get(int $userId, Host $host) foreach ($pool["used_by"] as $item) { if (strpos($item, '/1.0/storage-pools/') !== false) { $url = parse_url($item); + + if ($url == false) { + throw new \Exception("Couldn't parse '$item'", 1); + } + $project = "default"; if (isset($url["query"])) { parse_str($url["query"], $query); diff --git a/src/classes/Tools/Universe.php b/src/classes/Tools/Universe.php index 5947c5f0..54eb5015 100644 --- a/src/classes/Tools/Universe.php +++ b/src/classes/Tools/Universe.php @@ -14,16 +14,16 @@ class Universe { - private $fetchAllowedProjects; - private $hostList; - private $getAllClusters; - private $fetchUserProject; - private $fetchUserDetails; - private $getUserProject; - private $hasExtension; - private $routeApi; - - private $entityConversion = [ + private FetchAllowedProjects $fetchAllowedProjects; + private HostList $hostList; + private GetAllClusters $getAllClusters; + private FetchUserProject $fetchUserProject; + private FetchUserDetails $fetchUserDetails; + private GetUserProject $getUserProject; + private HasExtension $hasExtension; + private RouteApi $routeApi; + + private array $entityConversion = [ "instances"=>"/1.0/instances/", "images"=>"/1.0/images/", "profiles"=>"/1.0/profiles/", @@ -52,7 +52,7 @@ public function __construct( $this->routeApi = $routeApi; } - public function getEntitiesUserHasAccesTo(int $userId, string $entity = null) + public function getEntitiesUserHasAccesTo(int $userId, string $entity = null) :array { $isAdmin = $this->fetchUserDetails->isAdmin($userId) === "1"; @@ -187,7 +187,7 @@ public function getEntitiesUserHasAccesTo(int $userId, string $entity = null) ]; } - private function buildOldUsedBy($host) + private function buildOldUsedBy(Host $host) :array { $instances = $this->prefixString($host->instances->all(), "/1.0/instances/"); $images = $this->prefixString($host->images->all(), "/1.0/images/"); @@ -196,7 +196,7 @@ private function buildOldUsedBy($host) return array_merge($instances, $images, $profiles, $networks); } - private function prefixString($objs, $string) + private function prefixString(array $objs, string $string) :array { foreach ($objs as $i => $obj) { $objs[$i] = "$string$obj"; diff --git a/src/classes/Tools/User/AddUser.php b/src/classes/Tools/User/AddUser.php index 87b40077..3e9285bc 100644 --- a/src/classes/Tools/User/AddUser.php +++ b/src/classes/Tools/User/AddUser.php @@ -9,11 +9,11 @@ class AddUser { - private $validatePermissions; - private $insertUser; - private $fetchUserDetails; - private $checkPasswordPolicy; - + private ValidatePermissions $validatePermissions; + private InsertUser $insertUser; + private FetchUserDetails $fetchUserDetails; + private CheckPasswordPolicy $checkPasswordPolicy; + public function __construct( ValidatePermissions $validatePermissions, InsertUser $insertUser, @@ -26,7 +26,7 @@ public function __construct( $this->checkPasswordPolicy = $checkPasswordPolicy; } - public function add(int $userId, string $username, string $password) + public function add(int $userId, string $username, string $password) :bool { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/User/AllowedProjects/GetUserAllowedProjects.php b/src/classes/Tools/User/AllowedProjects/GetUserAllowedProjects.php index 2f0aea54..f8f096d6 100644 --- a/src/classes/Tools/User/AllowedProjects/GetUserAllowedProjects.php +++ b/src/classes/Tools/User/AllowedProjects/GetUserAllowedProjects.php @@ -9,11 +9,11 @@ class GetUserAllowedProjects { - private $validatePermissions; - private $fetchAllowedProjects; - private $getDetails; - private $fetchUserDetails; - + private ValidatePermissions $validatePermissions; + private FetchAllowedProjects $fetchAllowedProjects; + private GetDetails $getDetails; + private FetchUserDetails $fetchUserDetails; + public function __construct( ValidatePermissions $validatePermissions, FetchAllowedProjects $fetchAllowedProjects, diff --git a/src/classes/Tools/User/AllowedProjects/GrantAccess.php b/src/classes/Tools/User/AllowedProjects/GrantAccess.php index f7ee0413..64df070d 100644 --- a/src/classes/Tools/User/AllowedProjects/GrantAccess.php +++ b/src/classes/Tools/User/AllowedProjects/GrantAccess.php @@ -10,11 +10,11 @@ class GrantAccess { - private $validatePermissions; - private $fetchUserDetails; - private $insertUserAccess; - private $fetchAllowedProjects; - + private ValidatePermissions $validatePermissions; + private FetchUserDetails $fetchUserDetails; + private InsertUserAccess $insertUserAccess; + private FetchAllowedProjects $fetchAllowedProjects; + public function __construct( ValidatePermissions $validatePermissions, FetchUserDetails $fetchUserDetails, @@ -27,7 +27,7 @@ public function __construct( $this->fetchAllowedProjects = $fetchAllowedProjects; } - public function grant(int $userId, int $targetUserId, array $hosts, array $projects) + public function grant(int $userId, int $targetUserId, array $hosts, array $projects) :bool { $this->validatePermissions->isAdminOrThrow($userId); $isAdmin = (bool) $this->fetchUserDetails->isAdmin($targetUserId); diff --git a/src/classes/Tools/User/AllowedProjects/GrantAccessToProject.php b/src/classes/Tools/User/AllowedProjects/GrantAccessToProject.php index 6495b39b..4749bdfd 100644 --- a/src/classes/Tools/User/AllowedProjects/GrantAccessToProject.php +++ b/src/classes/Tools/User/AllowedProjects/GrantAccessToProject.php @@ -11,11 +11,11 @@ class GrantAccessToProject { - private $validatePermissions; - private $fetchUserDetails; - private $insertUserAccess; - private $fetchAllowedProjects; - + private ValidatePermissions $validatePermissions; + private FetchUserDetails $fetchUserDetails; + private InsertUserAccess $insertUserAccess; + private FetchAllowedProjects $fetchAllowedProjects; + public function __construct( ValidatePermissions $validatePermissions, FetchUserDetails $fetchUserDetails, @@ -28,7 +28,7 @@ public function __construct( $this->fetchAllowedProjects = $fetchAllowedProjects; } - public function grant(int $userId, array $targetUsers, Host $host, string $project) + public function grant(int $userId, array $targetUsers, Host $host, string $project) :bool { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/User/AllowedProjects/RevokeAccess.php b/src/classes/Tools/User/AllowedProjects/RevokeAccess.php index 9985db92..fe6ddd5b 100644 --- a/src/classes/Tools/User/AllowedProjects/RevokeAccess.php +++ b/src/classes/Tools/User/AllowedProjects/RevokeAccess.php @@ -10,11 +10,11 @@ class RevokeAccess { - private $validatePermissions; - private $fetchUserDetails; - private $deleteUserAccess; - private $deleteUserProject; - + private ValidatePermissions $validatePermissions; + private FetchUserDetails $fetchUserDetails; + private DeleteUserAccess $deleteUserAccess; + private DeleteUserProject $deleteUserProject; + public function __construct( ValidatePermissions $validatePermissions, FetchUserDetails $fetchUserDetails, diff --git a/src/classes/Tools/User/Dashboard/DeleteDashboard.php b/src/classes/Tools/User/Dashboard/DeleteDashboard.php index 381030ef..f2d8f764 100644 --- a/src/classes/Tools/User/Dashboard/DeleteDashboard.php +++ b/src/classes/Tools/User/Dashboard/DeleteDashboard.php @@ -6,14 +6,14 @@ class DeleteDashboard { - private $deleteUserDashboard; + private DeleteUserDashboard $deleteUserDashboard; public function __construct(DeleteUserDashboard $deleteUserDashboard) { $this->deleteUserDashboard = $deleteUserDashboard; } - public function delete(int $userId, int $dashboardId) + public function delete(int $userId, int $dashboardId) :void { //TODO Authenticate $this->deleteUserDashboard->delete($dashboardId); diff --git a/src/classes/Tools/User/Dashboard/Graphs/AddGraph.php b/src/classes/Tools/User/Dashboard/Graphs/AddGraph.php index b3d83931..768e736c 100644 --- a/src/classes/Tools/User/Dashboard/Graphs/AddGraph.php +++ b/src/classes/Tools/User/Dashboard/Graphs/AddGraph.php @@ -6,8 +6,8 @@ class AddGraph { - private $insertDashboardGraph; - + private InsertDashboardGraph $insertDashboardGraph; + public function __construct(InsertDashboardGraph $insertDashboardGraph) { $this->insertDashboardGraph = $insertDashboardGraph; @@ -22,7 +22,7 @@ public function add( int $metricId, string $filter, string $range - ) { + ) :void { $this->insertDashboardGraph->insert( $dashboardId, $name, diff --git a/src/classes/Tools/User/Dashboard/Graphs/DeleteGraph.php b/src/classes/Tools/User/Dashboard/Graphs/DeleteGraph.php index ee440d3f..57117b7a 100644 --- a/src/classes/Tools/User/Dashboard/Graphs/DeleteGraph.php +++ b/src/classes/Tools/User/Dashboard/Graphs/DeleteGraph.php @@ -6,14 +6,14 @@ class DeleteGraph { - private $deleteDashboardGraph; - + private DeleteDashboardGraph $deleteDashboardGraph; + public function __construct(DeleteDashboardGraph $deleteDashboardGraph) { $this->deleteDashboardGraph = $deleteDashboardGraph; } - public function delete(int $userId, int $graphId) + public function delete(int $userId, int $graphId) :void { //TODO Authenticate $this->deleteDashboardGraph->delete($graphId); diff --git a/src/classes/Tools/User/DeleteUser.php b/src/classes/Tools/User/DeleteUser.php index 8fe5f7e9..6029e086 100644 --- a/src/classes/Tools/User/DeleteUser.php +++ b/src/classes/Tools/User/DeleteUser.php @@ -13,14 +13,14 @@ class DeleteUser { - private $validatePermissions; - private $updateUserDeletedStatus; - private $updateUsername; - private $deleteUserAccess; - private $deleteUserApiTokens; - private $deleteBackupSchedules; - private $deleteRecordedActions; - private $updateLoginStatus; + private ValidatePermissions $validatePermissions; + private UpdateUserDeletedStatus $updateUserDeletedStatus; + private UpdateUsername $updateUsername; + private DeleteUserAccess $deleteUserAccess; + private DeleteUserApiTokens $deleteUserApiTokens; + private DeleteBackupSchedules $deleteBackupSchedules; + private DeleteRecordedActions $deleteRecordedActions; + private UpdateLoginStatus $updateLoginStatus; public function __construct( ValidatePermissions $validatePermissions, @@ -50,7 +50,7 @@ public function delete( int $removeApiKeys = 1, int $deleteAuditLogs = 0, int $deleteBackupSchedules = 0 - ) { + ) :bool { $this->validatePermissions->isAdminOrThrow($userId); $this->updateUserDeletedStatus->setDeleted($userId, $targetUserId); diff --git a/src/classes/Tools/User/GetUserProject.php b/src/classes/Tools/User/GetUserProject.php index 91fc04cb..a4e86614 100644 --- a/src/classes/Tools/User/GetUserProject.php +++ b/src/classes/Tools/User/GetUserProject.php @@ -9,11 +9,11 @@ class GetUserProject { - private $fetchAllowedProjects; - private $fetchUserProject; - private $setUserProject; - private $fetchUserDetails; - + private FetchAllowedProjects $fetchAllowedProjects; + private FetchUserProject $fetchUserProject; + private SetUserProject $setUserProject; + private FetchUserDetails $fetchUserDetails; + public function __construct( FetchAllowedProjects $fetchAllowedProjects, FetchUserProject $fetchUserProject, diff --git a/src/classes/Tools/User/GetUsers.php b/src/classes/Tools/User/GetUsers.php index 2cb5f748..4ada4262 100644 --- a/src/classes/Tools/User/GetUsers.php +++ b/src/classes/Tools/User/GetUsers.php @@ -7,16 +7,16 @@ class GetUsers { - private $validatePermissions; - private $fetchUsers; - + private ValidatePermissions $validatePermissions; + private FetchUsers $fetchUsers; + public function __construct(ValidatePermissions $validatePermissions, FetchUsers $fetchUsers) { $this->validatePermissions = $validatePermissions; $this->fetchUsers = $fetchUsers; } - public function getAll($userId) + public function getAll(int $userId) { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/User/Ldap/ImportLdapUsers.php b/src/classes/Tools/User/Ldap/ImportLdapUsers.php index d9153ad8..a052341e 100644 --- a/src/classes/Tools/User/Ldap/ImportLdapUsers.php +++ b/src/classes/Tools/User/Ldap/ImportLdapUsers.php @@ -11,11 +11,11 @@ class ImportLdapUsers { - private $ldap; - private $fetchUsers; - private $insertUser; - private $getSetting; - + private Ldap $ldap; + private FetchUsers $fetchUsers; + private InsertUser $insertUser; + private GetSetting $getSetting; + public function __construct(Ldap $ldap, FetchUsers $fetchUsers, InsertUser $insertUser, GetSetting $getSetting) { $this->ldap = $ldap; @@ -24,7 +24,7 @@ public function __construct(Ldap $ldap, FetchUsers $fetchUsers, InsertUser $inse $this->getSetting = $getSetting; } - public function import() + public function import() :bool { $knownLdapIds = $this->fetchUsers->fetchLdapIds(); $users = $this->findLdapUsers(); @@ -40,7 +40,7 @@ public function import() return true; } - private function findLdapUsers() + private function findLdapUsers() :array { $ldapconn = $this->ldap->getAdminBoundConnection(); @@ -62,7 +62,7 @@ private function findLdapUsers() $entries = ldap_get_entries($ldapconn, $result); - if ($entries["count"] == 0) { + if ($entries == false || $entries["count"] == 0) { throw new \Exception("No users found", 1); } diff --git a/src/classes/Tools/User/LogUserIn.php b/src/classes/Tools/User/LogUserIn.php index d22632a8..4f4355ab 100644 --- a/src/classes/Tools/User/LogUserIn.php +++ b/src/classes/Tools/User/LogUserIn.php @@ -16,13 +16,13 @@ class LogUserIn { - private $fetchUserDetails; - private $insertToken; - private $session; - private $fetchAllowedProjects; - private $getSetting; - private $ldap; - + private FetchUserDetails $fetchUserDetails; + private InsertToken $insertToken; + private Session $session; + private FetchAllowedProjects $fetchAllowedProjects; + private GetSetting $getSetting; + private Ldap $ldap; + public function __construct( FetchUserDetails $fetchUserDetails, InsertToken $insertToken, @@ -39,7 +39,7 @@ public function __construct( $this->ldap = $ldap; } - public function login(string $username, string $password) + public function login(string $username, string $password) :bool { $isLdapUser = !is_null($this->fetchUserDetails->fetchLdapId($username)); $passwordHash = $this->fetchUserDetails->fetchHash($username); @@ -61,16 +61,18 @@ public function login(string $username, string $password) throw new PasswordIncorrectException($username); } } elseif ($isLdapUser || $haveLdapServer) { + if (!$haveLdapServer) { + throw new \Exception("Can't login right now - contact admin", 1); + } + try { - $ldapconn = $this->ldap->getAdminBoundConnection($server); + $ldapconn = $this->ldap->getAdminBoundConnection(); } catch (\Throwable $e) { throw new \Exception("Can't login right now - contact admin", 1); } // Will throw if cant find user / cant bind & gives us back a // username that we should be able to fetch from DB $username = $this->ldap->verifyAccount($ldapconn, $username, $password); - } elseif ($isLdapUser || !$haveLdapServer) { - throw new \Exception("Can't login right now - contact admin", 1); } $userId = $this->fetchUserDetails->fetchId($username); diff --git a/src/classes/Tools/User/Password/CheckPasswordPolicy.php b/src/classes/Tools/User/Password/CheckPasswordPolicy.php index e93d085d..ac46dbf6 100644 --- a/src/classes/Tools/User/Password/CheckPasswordPolicy.php +++ b/src/classes/Tools/User/Password/CheckPasswordPolicy.php @@ -7,14 +7,14 @@ class CheckPasswordPolicy { - private $getSetting; - + private GetSetting $getSetting; + public function __construct(GetSetting $getSetting) { $this->getSetting = $getSetting; } - public function conforms($pwd) :void + public function conforms(string $pwd) :void { if ((bool) $this->getSetting->getSettingLatestValue(InstanceSettingsKeys::STRONG_PASSWORD_POLICY) === false) { return; diff --git a/src/classes/Tools/User/ResetPassword.php b/src/classes/Tools/User/ResetPassword.php index 9bdadbac..2236e5dc 100644 --- a/src/classes/Tools/User/ResetPassword.php +++ b/src/classes/Tools/User/ResetPassword.php @@ -9,11 +9,11 @@ class ResetPassword { - private $validatePermissions; - private $updatePasswordHash; - private $fetchUserDetails; - private $checkPasswordPolicy; - + private ValidatePermissions $validatePermissions; + private UpdatePasswordHash $updatePasswordHash; + private FetchUserDetails $fetchUserDetails; + private CheckPasswordPolicy $checkPasswordPolicy; + public function __construct( ValidatePermissions $validatePermissions, UpdatePasswordHash $updatePasswordHash, @@ -26,7 +26,7 @@ public function __construct( $this->checkPasswordPolicy = $checkPasswordPolicy; } - public function reset(int $userId, int $targetUserId, string $newPassword) + public function reset(int $userId, int $targetUserId, string $newPassword) :bool { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/User/SearchUsers.php b/src/classes/Tools/User/SearchUsers.php index 2369be7a..9573f05f 100644 --- a/src/classes/Tools/User/SearchUsers.php +++ b/src/classes/Tools/User/SearchUsers.php @@ -7,16 +7,16 @@ class SearchUsers { - private $validatePermissions; - private $fetchUsers; - + private ValidatePermissions $validatePermissions; + private FetchUsers $fetchUsers; + public function __construct(ValidatePermissions $validatePermissions, FetchUsers $fetchUsers) { $this->validatePermissions = $validatePermissions; $this->fetchUsers = $fetchUsers; } - public function search(int $userId, string $search) + public function search(int $userId, string $search) :array { $this->validatePermissions->isAdminOrThrow($userId); diff --git a/src/classes/Tools/User/SetUserProject.php b/src/classes/Tools/User/SetUserProject.php index 6338a966..d538cba8 100644 --- a/src/classes/Tools/User/SetUserProject.php +++ b/src/classes/Tools/User/SetUserProject.php @@ -7,9 +7,9 @@ class SetUserProject { - private $insertUserProject; - private $validatePermissions; - + private InsertUserProject $insertUserProject; + private ValidatePermissions $validatePermissions; + public function __construct( InsertUserProject $insertUserProject, ValidatePermissions $validatePermissions @@ -18,7 +18,7 @@ public function __construct( $this->validatePermissions = $validatePermissions; } - public function set(int $userId, int $hostId, string $project) + public function set(int $userId, int $hostId, string $project) :void { $this->validatePermissions->canAccessHostProjectOrThrow($userId, $hostId, $project); diff --git a/src/classes/Tools/User/ToggleAdminStatus.php b/src/classes/Tools/User/ToggleAdminStatus.php index 8f91f83f..d705adf2 100644 --- a/src/classes/Tools/User/ToggleAdminStatus.php +++ b/src/classes/Tools/User/ToggleAdminStatus.php @@ -8,8 +8,8 @@ class ToggleAdminStatus { - private $updateAdminStatus; - private $fetchUserDetails; + private UpdateAdminStatus $updateAdminStatus; + private FetchUserDetails $fetchUserDetails; public function __construct( UpdateAdminStatus $updateAdminStatus, @@ -19,7 +19,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function toggle(int $targetUser, int $status) + public function toggle(int $targetUser, int $status) :void { $isAlreadyAdmin = $this->fetchUserDetails->isAdmin($targetUser); diff --git a/src/classes/Tools/User/ToggleLoginStatus.php b/src/classes/Tools/User/ToggleLoginStatus.php index c3645031..8e91279a 100644 --- a/src/classes/Tools/User/ToggleLoginStatus.php +++ b/src/classes/Tools/User/ToggleLoginStatus.php @@ -3,13 +3,12 @@ namespace dhope0000\LXDClient\Tools\User; use dhope0000\LXDClient\Model\Users\UpdateLoginStatus; -use dhope0000\LXDClient\Tools\User\ValidatePermissions; use dhope0000\LXDClient\Model\Users\FetchUserDetails; class ToggleLoginStatus { - private $updateLoginStatus; - private $fetchUserDetails; + private UpdateLoginStatus $updateLoginStatus; + private FetchUserDetails $fetchUserDetails; public function __construct( UpdateLoginStatus $updateLoginStatus, @@ -19,7 +18,7 @@ public function __construct( $this->fetchUserDetails = $fetchUserDetails; } - public function toggle(int $targetUser, int $status) + public function toggle(int $targetUser, int $status) :void { $isLoginDisabled = $this->fetchUserDetails->isLoginDisabled($targetUser); diff --git a/src/classes/Tools/User/Tokens/DeleteToken.php b/src/classes/Tools/User/Tokens/DeleteToken.php index e86f8ced..79baf361 100644 --- a/src/classes/Tools/User/Tokens/DeleteToken.php +++ b/src/classes/Tools/User/Tokens/DeleteToken.php @@ -7,16 +7,16 @@ class DeleteToken { - private $fetchTokens; - private $removeToken; - + private FetchTokens $fetchTokens; + private RemoveToken $removeToken; + public function __construct(FetchTokens $fetchTokens, RemoveToken $removeToken) { $this->fetchTokens = $fetchTokens; $this->removeToken = $removeToken; } - public function delete(int $userId, int $tokenId) + public function delete(int $userId, int $tokenId) :bool { $tokenOwner = $this->fetchTokens->fetchTokenUser($tokenId); diff --git a/src/classes/Tools/User/UserSession.php b/src/classes/Tools/User/UserSession.php index 7fb4d209..7661463c 100644 --- a/src/classes/Tools/User/UserSession.php +++ b/src/classes/Tools/User/UserSession.php @@ -8,10 +8,10 @@ class UserSession { - private $invalidateToken; - private $session; - private $validateToken; - + private InvalidateToken $invalidateToken; + private Session $session; + private ValidateToken $validateToken; + public function __construct( InvalidateToken $invalidateToken, Session $session, @@ -22,25 +22,25 @@ public function __construct( $this->validateToken = $validateToken; } - public function isLoggedIn() + public function isLoggedIn() :bool { return !empty($this->getUserId()) && $this->validateToken->validate($this->getUserId(), $this->session->get("wsToken")); } - public function logout() + public function logout() :bool { $this->invalidateToken->invalidate($this->session->get("userId"), $this->session->get("wsToken")); $this->session->clear(); return true; } - public function getToken() + public function getToken() :string { return $this->session->get("wsToken"); } - public function getUserId() + public function getUserId() :int { - return $this->session->get("userId"); + return (int) $this->session->get("userId"); } } diff --git a/src/classes/Tools/User/ValidatePermissions.php b/src/classes/Tools/User/ValidatePermissions.php index 127f7fcd..b4dae7a7 100644 --- a/src/classes/Tools/User/ValidatePermissions.php +++ b/src/classes/Tools/User/ValidatePermissions.php @@ -7,9 +7,9 @@ class ValidatePermissions { - private $fetchUserDetails; - private $fetchAllowedProjects; - + private FetchUserDetails $fetchUserDetails; + private FetchAllowedProjects $fetchAllowedProjects; + public function __construct( FetchUserDetails $fetchUserDetails, FetchAllowedProjects $fetchAllowedProjects @@ -23,7 +23,7 @@ public function isAdmin(int $userId) :bool return (bool) $this->fetchUserDetails->isAdmin($userId); } - public function canAccessHostProjectOrThrow(int $userId, int $hostId, string $project) + public function canAccessHostProjectOrThrow(int $userId, int $hostId, string $project) :bool { $isAdmin = $this->isAdmin($userId); if ($isAdmin) { diff --git a/src/classes/Tools/User/ValidateToken.php b/src/classes/Tools/User/ValidateToken.php index 1c472500..8f20e759 100644 --- a/src/classes/Tools/User/ValidateToken.php +++ b/src/classes/Tools/User/ValidateToken.php @@ -6,14 +6,14 @@ class ValidateToken { - private $fetchTokens; - + private FetchTokens $fetchTokens; + public function __construct(FetchTokens $fetchTokens) { $this->fetchTokens = $fetchTokens; } - public function validate(int $userId, string $token) + public function validate(int $userId, string $token) :bool { $latestToken = $this->fetchTokens->fetchLatestNonPermanentToken($userId); diff --git a/src/classes/Tools/Utilities/DateTools.php b/src/classes/Tools/Utilities/DateTools.php index eed0f229..d5f1a362 100644 --- a/src/classes/Tools/Utilities/DateTools.php +++ b/src/classes/Tools/Utilities/DateTools.php @@ -17,7 +17,7 @@ public function hoursRange( string $keyPrefix = '', bool $stopAtNow = false, int $startMinute = 0 - ) { + ) :array { $times = array(); $x = (int) (new \DateTimeImmutable())->format("Hi"); for ($h = $startHour; $h < $endHour; $h++) { diff --git a/src/classes/Tools/Utilities/IsUpToDate.php b/src/classes/Tools/Utilities/IsUpToDate.php index 333bc35d..6e2facd4 100644 --- a/src/classes/Tools/Utilities/IsUpToDate.php +++ b/src/classes/Tools/Utilities/IsUpToDate.php @@ -4,7 +4,7 @@ class IsUpToDate { - public static function isIt() + public static function isIt() :array { $x = [ "master"=>false, @@ -31,6 +31,11 @@ public static function isIt() // Close request to clear up some resources curl_close($curl); + if (!is_string($resp)) { + $x["cantSeeGithub"] = true; + return $x; + } + $githubData = json_decode($resp, true); if (json_last_error()) { diff --git a/src/classes/Tools/Utilities/StringTools.php b/src/classes/Tools/Utilities/StringTools.php index 01916580..2f912f0b 100644 --- a/src/classes/Tools/Utilities/StringTools.php +++ b/src/classes/Tools/Utilities/StringTools.php @@ -18,10 +18,15 @@ class StringTools * to select from * @return string */ - public static function random($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') + public static function random($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') :string { $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; + + if ($max <= 0) { + throw new \Exception("Keyspace length must be > 0", 1); + } + for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } @@ -31,7 +36,7 @@ public static function random($length, $keyspace = '0123456789abcdefghijklmnopqr /** * https://stackoverflow.com/a/2790919/4008082 */ - public function stringStartsWith(string $string, string $query) + public function stringStartsWith(string $string, string $query) :bool { return substr($string, 0, strlen($query)) === $query; } @@ -39,7 +44,7 @@ public function stringStartsWith(string $string, string $query) /** * https://stackoverflow.com/a/9826656/4008082 */ - public static function getStringBetween(string $string, string $start, string $end) + public static function getStringBetween(string $string, string $start, string $end) :string { $string = ' ' . $string; $ini = strpos($string, $start); @@ -51,11 +56,15 @@ public static function getStringBetween(string $string, string $start, string $e return substr($string, $ini, $len); } - public static function usedByStringsToLinks(Host $host, array $usedBy) + public static function usedByStringsToLinks(Host $host, array $usedBy) :array { foreach ($usedBy as $index => $item) { $parts = parse_url($item); + if ($parts == false) { + throw new \Exception("Couldn't parse '$item'", 1); + } + $query = []; if (isset($parts["query"])) { @@ -69,7 +78,7 @@ public static function usedByStringsToLinks(Host $host, array $usedBy) $itemProject = "default"; if (isset($query["project"])) { - $itemProject = $query["project"]; + $itemProject = (string) $query["project"]; } $icon = ""; diff --git a/src/classes/Tools/Utilities/UsedByFilter.php b/src/classes/Tools/Utilities/UsedByFilter.php index d84bdf2b..23f2b202 100644 --- a/src/classes/Tools/Utilities/UsedByFilter.php +++ b/src/classes/Tools/Utilities/UsedByFilter.php @@ -16,8 +16,10 @@ public function __construct(FetchAllowedProjects $fetchAllowedProjects, FetchUse $this->fetchAllowedProjects = $fetchAllowedProjects; $this->fetchUserDetails = $fetchUserDetails; } - - public function filterUserProjects(int $userId, Host $host, array $usedBy) + /** + * @return array + */ + public function filterUserProjects(int $userId, Host $host, array $usedBy) :array { $isAdmin = $this->fetchUserDetails->isAdmin($userId);