-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add new tests for RepositoriesGenerateCommand, although some tests for the SelectEntries builder in there is still missing - Some slight restructuring and correction of phpcs ruleset
- Loading branch information
Showing
20 changed files
with
745 additions
and
283 deletions.
There are no files selected for viewing
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
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
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
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,85 @@ | ||
<?php | ||
|
||
namespace Squirrel\Entities\Action; | ||
|
||
/** | ||
* Iterator basis for SelectEntries and MultiSelectEntries to be used in a foreach loop | ||
*/ | ||
trait SelectIteratorTrait | ||
{ | ||
/** | ||
* @var object | ||
*/ | ||
private $repository; | ||
|
||
/** | ||
* @var array SELECT query to execute | ||
*/ | ||
private $query = []; | ||
|
||
/** | ||
* @var object|null | ||
*/ | ||
private $selectReference; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $position = -1; | ||
|
||
/** | ||
* @var object|array|null | ||
*/ | ||
private $lastResult; | ||
|
||
/** | ||
* @return object|array|null | ||
*/ | ||
public function current() | ||
{ | ||
return $this->lastResult; | ||
} | ||
|
||
public function next() | ||
{ | ||
if (isset($this->selectReference)) { | ||
$this->lastResult = $this->repository->fetch($this->selectReference); | ||
$this->position++; | ||
} | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function key() | ||
{ | ||
return $this->position; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function valid() | ||
{ | ||
return ( $this->lastResult === null ? false : true ); | ||
} | ||
|
||
public function rewind() | ||
{ | ||
$this->clear(); | ||
|
||
$this->selectReference = $this->repository->select($this->query); | ||
|
||
$this->next(); | ||
} | ||
|
||
public function clear() | ||
{ | ||
if (isset($this->selectReference)) { | ||
$this->repository->clear($this->selectReference); | ||
} | ||
$this->position = -1; | ||
$this->selectReference = null; | ||
$this->lastResult = null; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Squirrel\Entities\Generate; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
class PHPFilesInDirectoryGetContents | ||
{ | ||
public function __invoke(string $directory) | ||
{ | ||
$sourceFinder = new Finder(); | ||
$sourceFinder->in($directory)->files()->name('*.php')->sortByName(); | ||
|
||
// Go through files which were found | ||
foreach ($sourceFinder as $file) { | ||
// Safety check because Finder can return false if the file was not found | ||
if ($file->getRealPath() === false) { | ||
throw new \InvalidArgumentException('File in source directory not found'); | ||
} | ||
|
||
// Get file contents | ||
$fileContents = \file_get_contents($file->getRealPath()); | ||
|
||
// Another safety check because file_get_contents can return false if the file was not found | ||
if ($fileContents===false) { | ||
throw new \InvalidArgumentException('File in source directory could not be retrieved'); | ||
} | ||
|
||
yield [ | ||
'filename' => $file->getFilename(), | ||
'path' => $file->getPath(), | ||
'contents' => $fileContents, | ||
]; | ||
} | ||
} | ||
} |
Oops, something went wrong.