Skip to content

Commit

Permalink
Merge pull request #149 from renoki-co/feature/psalm
Browse files Browse the repository at this point in the history
[fix] Static Analysis
  • Loading branch information
rennokki authored Oct 25, 2021
2 parents 0ef64c4 + 0f4b135 commit df08df5
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
run: |
kubectl apply -f https://raw.githubusercontent.com/bitnami-labs/sealed-secrets/main/helm/sealed-secrets/crds/sealedsecret-crd.yaml
- name: Run static analysis
run: |
vendor/bin/psalm
- name: Run tests
run: |
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"require-dev": {
"mockery/mockery": "^1.4",
"orchestra/testbench": "^5.0|^6.0"
"orchestra/testbench": "^5.0|^6.0",
"vimeo/psalm": "4.11"
},
"config": {
"sort-packages": true
Expand Down
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MoreSpecificReturnType errorLevel="suppress" />
</issueHandlers>
</psalm>
4 changes: 2 additions & 2 deletions src/K8s.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function fromYaml($cluster, string $yaml)
/**
* Load Kind configuration from an YAML file.
*
* @param \RenokiCo\PhpK8s\Kinds\KubernetesCluster|null $cluster
* @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster
* @param string $path
* @param Closure|null $callback
* @return \RenokiCo\PhpK8s\Kinds\K8sResource|array[\RenokiCo\PhpK8s\Kinds\K8sResource]
Expand All @@ -73,7 +73,7 @@ public static function fromYamlFile($cluster, string $path, Closure $callback =
* replace all variables in curly braces with the values from
* the given array.
*
* @param \RenokiCo\PhpK8s\Kinds\KubernetesCluster|null $cluster
* @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster
* @param string $path
* @param array $replace
* @param \Closure|null $callback
Expand Down
6 changes: 3 additions & 3 deletions src/Kinds/K8sCronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getJobTemplate(bool $asInstance = true)
$template = $this->getSpec('jobTemplate', []);

if ($asInstance) {
$template = new K8sJob($this->cluster ?? null, $template);
$template = new K8sJob($this->cluster, $template);
}

return $template;
Expand All @@ -70,7 +70,7 @@ public function getJobTemplate(bool $asInstance = true)
/**
* Set the schedule for the cronjob.
*
* @param string|\Cron\CronExpression $schedule
* @param \Cron\CronExpression|string $schedule
* @return $this
*/
public function setSchedule($schedule)
Expand All @@ -86,7 +86,7 @@ public function setSchedule($schedule)
* Retrieve the schedule.
*
* @param bool $asInstance
* @return string|\Cron\CronExpression
* @return \Cron\CronExpression|string
*/
public function getSchedule(bool $asInstance = true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kinds/K8sPod.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function getPodIps(): array
/**
* Get the pod host IP.
*
* @return string\null
* @return string|null
*/
public function getHostIp()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Kinds/K8sResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class K8sResource implements Arrayable, Jsonable
/**
* Create a new resource.
*
* @param null|RenokiCo\PhpK8s\KubernetesCluster $cluster
* @param \RenokiCo\PhpK8s\KubernetesCluster|null $cluster
* @param array $attributes
* @return void
*/
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function getUniqueCrdMacro(string $kind = null, string $defaultVer
/**
* Get the plural resource name.
*
* @return string|null
* @return string
*/
public static function getPlural()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kinds/K8sServiceAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class K8sServiceAccount extends K8sResource implements InteractsWithK8sCluster,
/**
* Attach a new secret to the secrets list.
*
* @param string|\RenokiCo\PhpK8s\Kings\K8sSecret $secret
* @param \RenokiCo\PhpK8s\Kinds\K8sSecret|string $secret
* @return $this
*/
public function addSecret($secret)
Expand Down
2 changes: 1 addition & 1 deletion src/Kinds/K8sStatefulSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setUpdateStrategy(string $strategy, int $partition = 0)
/**
* Set the statefulset service.
*
* @param string|\RenokiCo\PhpK8s\Kinds\K8sService $service
* @param \RenokiCo\PhpK8s\Kinds\K8sService|string $service
* @return $this
*/
public function setService($service)
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function setResourceClass(string $resourceClass)
*
* @param string $operation
* @param string $path
* @param string|Closure $payload
* @param string|null|Closure $payload
* @param array $query
* @return mixed
*
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Cluster/ChecksClusterVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait ChecksClusterVersion
/**
* The Kubernetes cluster version.
*
* @var \vierbergenlars\SemVer\version
* @var \vierbergenlars\SemVer\version|null
*/
protected $kubernetesVersion;

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/Cluster/MakesWebsocketCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RenokiCo\PhpK8s\Traits\Cluster;

use Closure;
use Exception;
use Illuminate\Support\Str;
use Ratchet\Client\Connector as WebSocketConnector;
use React\EventLoop\Factory as ReactFactory;
Expand Down Expand Up @@ -183,7 +184,7 @@ protected function makeWsRequest(string $path, Closure $callback = null, array $
'output' => $message,
];
});
}, function ($e) {
}, function (Exception $e) {
throw $e;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Resource/HasName.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function whereName(string $name)
/**
* Get the name.
*
* @return string|null
* @return string
*/
public function getName()
{
return $this->getAttribute('metadata.name', null);
return $this->getAttribute('metadata.name');
}
}
4 changes: 2 additions & 2 deletions src/Traits/Resource/HasNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function setDefaultNamespace(string $namespace)
/**
* Set the namespace of the resource.
*
* @param string|\RenokiCo\PhpK8s\Kinds\K8sNamespace $namespace
* @param \RenokiCo\PhpK8s\Kinds\K8sNamespace|string $namespace
* @return $this
*/
public function setNamespace($namespace)
Expand All @@ -57,7 +57,7 @@ public function setNamespace($namespace)
/**
* Alias for ->setNamespace().
*
* @param string|\RenokiCo\PhpK8s\Kinds\K8sNamespace $namespace
* @param \RenokiCo\PhpK8s\Kinds\K8sNamespace|string $namespace
* @return $this
*/
public function whereNamespace($namespace)
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Resource/HasStorageClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait HasStorageClass
/**
* Set the storageClassName parameter.
*
* @param string|\RenokiCo\PhpK8s\Kinds\K8sStorageClass
* @param \RenokiCo\PhpK8s\Kinds\K8sStorageClass|string $storageClass
* @return $this
*/
public function setStorageClass($storageClass)
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Resource/HasTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getTemplate(bool $asInstance = true)
$template = $this->getSpec('template', []);

if ($asInstance) {
$template = new K8sPod($this->cluster ?? null, $template);
$template = new K8sPod($this->cluster, $template);
}

return $template;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/RunsClusterOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public function exec(
/**
* Attach to the current resource.
*
* @param
* @param \Closure|null $callback
* @param string|null $container
* @param array $query
* @return string
Expand Down

0 comments on commit df08df5

Please sign in to comment.