-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow parse expressions with Request::validate facade usage (#895)
* Allow parse expressions with Request::validate facade usage * fix missing import * creating tests
- Loading branch information
1 parent
3aa44f8
commit 76a06e3
Showing
4 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/Extracting/Shared/ValidationRulesFinders/RequestValidateFacade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Knuckles\Scribe\Extracting\Shared\ValidationRulesFinders; | ||
|
||
use PhpParser\Node; | ||
|
||
/** | ||
* This class looks for | ||
* $anyVariable = Request::validate(...); | ||
* or just | ||
* Request::validate(...); | ||
* | ||
* Also supports `->validateWithBag('', ...)` | ||
*/ | ||
class RequestValidateFacade | ||
{ | ||
public static function find(Node $node) | ||
{ | ||
if (!($node instanceof Node\Stmt\Expression)) return; | ||
|
||
$expr = $node->expr; | ||
if ($expr instanceof Node\Expr\Assign) { | ||
$expr = $expr->expr; // If it's an assignment, get the expression on the RHS | ||
} | ||
|
||
if ( | ||
$expr instanceof Node\Expr\StaticCall | ||
&& in_array((string) $expr->class, ['Request', \Illuminate\Support\Facades\Request::class]) | ||
) { | ||
if ($expr->name->name == "validate") { | ||
return $expr->args[0]->value; | ||
} | ||
|
||
if ($expr->name->name == "validateWithBag") { | ||
return $expr->args[1]->value; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters