Skip to content

Commit

Permalink
Merge pull request #514 from jolicode/fix-fingerprint
Browse files Browse the repository at this point in the history
Fix BC layer for `fingerprint()` function
  • Loading branch information
pyrech authored Sep 3, 2024
2 parents 8dc9ad1 + 423b2bb commit 2e3cc97
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 64 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Not released yet

## 0.18.1 (2024-09-03)

* Fix BC layer for `fingerprint()` function

## 0.18.0 (2024-08-27)

### Features
Expand All @@ -18,7 +22,7 @@

### Fixes

* Add an id parameter to fingerprint to avoid bad cache hit
* Add an id parameter to `fingerprint()` to avoid bad cache hit
* Fix completion when update is available
* Fix repack when there is composer dependencies to castor
* Fix wait_for_docker_container example to avoid checking previous docker logs
Expand Down
2 changes: 1 addition & 1 deletion examples/args.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function args(
#[AsTask(description: 'Dumps all arguments and options, without configuration')]
function another_args(
string $required,
int $test2 = 1
int $test2 = 1,
): void {
io()->writeln($required . ' ' . $test2);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function task_with_a_fingerprint(): void
io()->writeln('Cool, no fingerprint! Executing...');
},
id: 'my_fingerprint_check',
fingerprint: my_fingerprint_check()
fingerprint: my_fingerprint_check(),
);

io()->writeln('Cool! I finished!');
Expand All @@ -44,7 +44,7 @@ function task_with_complete_fingerprint_check(): void

#[AsTask(description: 'Check if the fingerprint has changed before executing a callback (with force option)')]
function task_with_a_fingerprint_and_force(
#[AsOption(description: 'Force the callback to run even if the fingerprint has not changed')] bool $force = false
#[AsOption(description: 'Force the callback to run even if the fingerprint has not changed')] bool $force = false,
): void {
io()->writeln('Hello Task with Fingerprint!');

Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/AsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AsContext
{
public function __construct(
public string $name = '',
public bool $default = false
public bool $default = false,
) {
}
}
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Application extends SymfonyApplication
{
public const NAME = 'castor';
public const VERSION = 'v0.18.0';
public const VERSION = 'v0.18.1';

private Command $command;

Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Notifier
public function __construct(
private DefaultNotifier $notifier,
private LoggerInterface $logger,
private ContextRegistry $contextRegistry
private ContextRegistry $contextRegistry,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function load(
array $currentFunctions,
array $currentClasses,
InputInterface $input,
OutputInterface $output
OutputInterface $output,
): void {
if ($mount->allowRemotePackage) {
$this->composer->install($mount->path);
Expand Down
25 changes: 23 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,34 @@ function fingerprint_save(string $id, ?string $fingerprint = null): void
Container::get()->fingerprintHelper->postProcessFingerprintForHash($id, $fingerprint);
}

function fingerprint(callable $callback, string $id, ?string $fingerprint = null, bool $force = false): bool
// function fingerprint(callable $callback, string $fingerprint, bool $force = false): bool
/**
* @param string $id
* @param string $fingerprint
*/
function fingerprint(callable $callback, /* string */ $id = null, /* string */ $fingerprint = null, bool $force = false): bool
{
// Could only occur due du BC layer
if (null === $fingerprint && null === $id) {
throw new \LogicException('You must provide "id" and "fingerprint" argument.');
}
// @phpstan-ignore function.impossibleType
if (\is_bool($fingerprint)) {
trigger_deprecation('castor/castor', '0.18.0', 'since 0.18 fingerprint functions require an "id" and "fingerprint" argument.');

$force = $fingerprint;
$fingerprint = $id;
}
if (null === $fingerprint) {
trigger_deprecation('castor/castor', '0.18.0', 'since 0.18 fingerprint functions require an id argument.');
trigger_deprecation('castor/castor', '0.18.0', 'since 0.18 fingerprint functions require an "fingerprint" argument.');

$fingerprint = $id;
}
if (null === $id) {
trigger_deprecation('castor/castor', '0.18.0', 'since 0.18 fingerprint functions require a "id" argument.');

$id = $fingerprint;
}

if ($force || !fingerprint_exists($id, $fingerprint)) {
$callback();
Expand Down
2 changes: 1 addition & 1 deletion tools/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "project",
"license": "MIT",
"require": {
"friendsofphp/php-cs-fixer": "^3.62.0"
"friendsofphp/php-cs-fixer": "^3.64.0"
},
"config": {
"platform": {
Expand Down
Loading

0 comments on commit 2e3cc97

Please sign in to comment.