Skip to content

Commit 8f0477a

Browse files
harm-lessharm-less
authored andcommitted
Milestone. Got 100% code coverage
1 parent 119ddf4 commit 8f0477a

File tree

13 files changed

+188
-78
lines changed

13 files changed

+188
-78
lines changed

samples/FQ/Samples/Simple.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function __construct() {
2020

2121
public function queryFile1FromChild1() {
2222

23+
//pr($this->queryPath('File2'));
24+
//var_dump($this->queryPath('does-not'));
25+
2326

2427
$builder = new FilesQueryBuilder($this);
2528
$builder->excludeRootDirs('root1')->includeChildDirs('child1')->fileName('File1');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File1 {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File2 {
4+
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
define('BOOTSTRAP_ROOT_1', true);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File1 {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File2 {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File1 {
4+
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
define('BOOTSTRAP_ROOT_2', true);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class File1 {
4+
5+
}

src/FQ/Files.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use FQ\Dirs\RootDir;
99
use FQ\Exceptions\FilesException;
1010
use FQ\Query\FilesQuery;
11+
use FQ\Query\FilesQueryRequirements;
1112
use FQ\Query\Selection\ChildSelection;
1213
use FQ\Query\Selection\RootSelection;
1314

@@ -31,7 +32,6 @@ class Files {
3132
*/
3233
private $_query;
3334

34-
3535
const DEFAULT_EXTENSION = 'php';
3636

3737
function __construct() {
@@ -68,7 +68,7 @@ public function rootDirs() {
6868
* @param RootDir $rootDir RootDir that will be checked
6969
* @return bool Returns true if RootDir is part of this files instance
7070
*/
71-
public function isRootDirOf(RootDir $rootDir) {
71+
public function containsRootDir(RootDir $rootDir) {
7272
return $this->_rootDirs()->isInCollection($rootDir);
7373
}
7474

@@ -140,7 +140,7 @@ public function childDirs() {
140140
* @param ChildDir $childDir Dir that will be checked
141141
* @return bool Returns true if dir is part of this files instance
142142
*/
143-
public function isChildDirOf(ChildDir $childDir) {
143+
public function containsChildDir(ChildDir $childDir) {
144144
return $this->_childDirs()->isInCollection($childDir);
145145
}
146146

@@ -207,9 +207,6 @@ protected function isValid() {
207207
return true;
208208
}
209209

210-
211-
212-
213210
/**
214211
* @param string|RootDir $rootDir
215212
* @param string|ChildDir $childDir
@@ -229,31 +226,31 @@ public function getFullPath($rootDir, $childDir) {
229226

230227
/**
231228
* @param string $fileName
232-
* @param null|string|ChildDir[] $children
229+
* @param ChildSelection $childSelection
230+
* @param RootSelection $rootSelection
233231
* @param bool $reverseLoad
234-
* @return null|string
232+
* @return false|string
235233
*/
236-
public function filePath($fileName, $children = null, $reverseLoad = true) {
237-
$query = $this->query($children);
234+
public function queryPath($fileName, ChildSelection $childSelection = null, RootSelection $rootSelection = null, $reverseLoad = true) {
235+
$query = $this->query($rootSelection, $childSelection, true, true);
238236
$query->reverse($reverseLoad);
239-
$query->requirements(FilesQuery::LEVELS_ONE);
240-
$query->run($fileName);
241-
242-
$paths = $query->listPaths();
243-
if (count($paths)) {
244-
foreach ($paths as $path) return $path;
237+
$query->requirements(FilesQueryRequirements::LEVELS_ONE);
238+
if ($query->run($fileName)) {
239+
$paths = $query->listPaths();
240+
if (count($paths)) foreach ($paths as $path) return $path;
245241
}
246242
return false;
247243
}
248244

249245
/**
250246
* @param string $fileName
251-
* @param null|string|ChildDir[] $children
247+
* @param ChildSelection $childSelection
248+
* @param RootSelection $rootSelection
252249
* @param bool $reverseLoad
253250
* @return bool
254251
*/
255-
public function loadFile($fileName, $children = null, $reverseLoad = true) {
256-
$path = $this->filePath($fileName, $children, $reverseLoad);
252+
public function loadFile($fileName, ChildSelection $childSelection = null, RootSelection $rootSelection = null, $reverseLoad = true) {
253+
$path = $this->queryPath($fileName, $childSelection, $rootSelection, $reverseLoad);
257254
if ($path) {
258255
return $this->requireOnce($path);
259256
}
@@ -268,26 +265,32 @@ public function loadFile($fileName, $children = null, $reverseLoad = true) {
268265
* @param bool $reverseLoad
269266
* @return bool
270267
*/
271-
public function loadFiles($fileName, RootSelection $rootDirs = null, ChildSelection $children = null, $requiredLevels = FilesQuery::LEVELS_ONE, $reverseLoad = true) {
272-
$query = $this->query($rootDirs, $children, true, true);
273-
$query->reverse($reverseLoad);
274-
$query->requirements($requiredLevels);
275-
$query->run($fileName);
276-
277-
foreach ($query->listPaths() as $file) {
278-
$this->requireOnce($file);
268+
public function loadFiles($fileName, RootSelection $rootDirs = null, ChildSelection $children = null, $requiredLevels = FilesQueryRequirements::LEVELS_ONE, $reverseLoad = true)
269+
{
270+
$query = $this->query($rootDirs, $children, true, true);
271+
$query->reverse($reverseLoad);
272+
$query->requirements($requiredLevels);
273+
if ($query->run($fileName)) {
274+
$paths = $query->listPaths();
275+
if (count($paths)) {
276+
foreach ($query->listPaths() as $file) {
277+
$this->includeOnce($file);
278+
}
279+
return true;
280+
}
279281
}
280-
return true;
282+
return false;
281283
}
282284

283285
/**
284286
* @param string $fileName
285287
* @param RootSelection $rootDirs
286288
* @param ChildSelection $children
287-
* @return FilesQuery
289+
* @return array
288290
*/
289-
public function getFilePaths($fileName, RootSelection $rootDirs = null, ChildSelection $children = null) {
290-
$query = $this->queryRun($fileName, $rootDirs, $children, true, true);
291+
public function queryPaths($fileName, RootSelection $rootDirs = null, ChildSelection $children = null) {
292+
$query = $this->query($rootDirs, $children, true, true);
293+
$query->run($fileName);
291294
return $query->listPaths();
292295
}
293296

@@ -298,7 +301,8 @@ public function getFilePaths($fileName, RootSelection $rootDirs = null, ChildSel
298301
* @return bool
299302
*/
300303
public function fileExists($fileName, RootSelection $rootDirs = null, ChildSelection $children = null) {
301-
$query = $this->queryRun($fileName, $rootDirs, $children, true, true);
304+
$query = $this->query($rootDirs, $children, true, true);
305+
$query->run($fileName);
302306
return $query->hasPaths();
303307
}
304308

@@ -323,19 +327,15 @@ public function query(RootSelection $rootDirs = null, ChildSelection $children =
323327
}
324328

325329
/**
326-
* A basic query wrapper
330+
* Very simple include function wrapper. Ready to be extended when necessary.
327331
*
328-
* @param string $fileName
329-
* @param RootSelection $rootDirs
330-
* @param ChildSelection $children
331-
* @param bool $resetQuery
332-
* @param bool $resetSelection
333-
* @return FilesQuery
332+
* @param string $file
333+
* @return bool
334334
*/
335-
public function queryRun($fileName, RootSelection $rootDirs = null, ChildSelection $children = null, $resetQuery = true, $resetSelection = false) {
336-
$query = $this->query($rootDirs, $children, $resetQuery, $resetSelection);
337-
$query->run($fileName);
338-
return $query;
335+
protected function includeOnce($file) {
336+
/** @noinspection PhpIncludeInspection */
337+
include_once $file;
338+
return true;
339339
}
340340

341341
/**

0 commit comments

Comments
 (0)