Skip to content

Commit

Permalink
Simplify recipes and fix Psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Oct 3, 2024
1 parent 2791ae2 commit 3f11e9e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
30 changes: 26 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@
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"
findUnusedVariablesAndParams="false"
findUnusedPsalmSuppress="false"
findUnusedCode="false"
findUnusedBaselineEntry="false"
errorLevel="1"
findUnusedCode="false"
findUnusedPsalmSuppress="false"
findUnusedVariablesAndParams="false"
errorLevel="2"
>
<projectFiles>
<directory name="src"/>

<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedFunction>
<errorLevel type="suppress">
<!-- This could be fixed by adding the Deployer's functions.php to our autoload, but that makes our deploy.php file not work -->
<referencedFunction name="Deployer\after"/>
<referencedFunction name="Deployer\ask"/>
<referencedFunction name="Deployer\askConfirmation"/>
<referencedFunction name="Deployer\before"/>
<referencedFunction name="Deployer\get"/>
<referencedFunction name="Deployer\has"/>
<referencedFunction name="Deployer\input"/>
<referencedFunction name="Deployer\invoke"/>
<referencedFunction name="Deployer\run"/>
<referencedFunction name="Deployer\set"/>
<referencedFunction name="Deployer\task"/>
<referencedFunction name="Deployer\test"/>
<referencedFunction name="Deployer\output"/>
<referencedFunction name="Deployer\upload"/>
</errorLevel>
</UndefinedFunction>
</issueHandlers>
</psalm>
18 changes: 2 additions & 16 deletions src/recipe/setono_dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,9 @@

use function Deployer\after;
use function Deployer\before;
use Deployer\Deployer;

require_once __DIR__ . '/../task/setono_dotenv.php';
require_once 'task/setono_dotenv.php';

after('deploy:update_code', 'dotenv:prepare');

$deployer = Deployer::get();

/**
* The task deploy:cache:clear is defined in Symfony related recipes and both the cache clear
* and cache warmup tasks sometimes depend on environment variables. Therefore, it's a good idea
* to have environment variables defined before running these tasks.
*/
if ($deployer->tasks->has('deploy:cache:clear')) {
before('deploy:cache:clear', 'dotenv:update');
} else {
before('deploy:symlink', 'dotenv:update');
}

after('deploy:vendors', 'dotenv:update');
before('dotenv:update', 'dotenv:generate');
9 changes: 7 additions & 2 deletions src/task/setono_dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
break;
}

if (!preg_match('/^[a-zA-Z_]\w*=.+$/', $newValue)) {
output()->writeln('<error>Invalid input. Please provide a valid environment variable and value (ENV_VAR=value)</error>');

continue;
}

/** @psalm-suppress PossiblyUndefinedArrayOffset */
[$key, $val] = explode('=', $newValue, 2);

// Here we add/overwrite the value from the user
Expand Down Expand Up @@ -206,8 +213,6 @@ function evaluatePhpEnvFile(string $path): array

/** @var array<string, scalar> $res */
$res = eval('?>' . $data);
Assert::isArray($res);
Assert::allScalar($res);

return $res;
}

0 comments on commit 3f11e9e

Please sign in to comment.