Skip to content

Commit

Permalink
NEW Use symfony/finder to perform file lookups in checks (#10)
Browse files Browse the repository at this point in the history
* NEW Use symfony/finder to perform file lookups in checks
* Allow doc or docs for documentation folder name, add test for class
* Support code and src for PHP source
  • Loading branch information
robbieaverill authored and Sam Minnée committed May 10, 2018
1 parent fd6eda7 commit 7847da4
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 86 deletions.
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -23,9 +23,10 @@ Please see the readme in that module for more information on using it.

## Requirements

* [symfony/finder](https://symfony.com/doc/current/components/finder.html) 3 or 4
* [symfony/yaml](https://symfony.com/doc/current/components/yaml.html) 3 or 4

**Note:** If you have conflicts with either symfony/yaml or symfony/console (if using the Composer plugin)
**Note:** If you have conflicts with any of the symfony components (if using the Composer plugin)
during installation, you may need to manually require an older version of one or both of those packages, e.g.:

```
Expand Down Expand Up @@ -58,21 +59,21 @@ The return data from `CheckSuite::getCheckDetails` is an array with the followin

```json
{
"good_code_coverage": {
"description": "Has a \"good\" level of code coverage (greater than 40%, requires slug)",
"points": 5,
"maximum": 5
},
"has_code_of_conduct_file": {
"description": "Has a code of conduct file",
"points": 2,
"maximum": 2
},
"coding_standards": {
"description": "The PHP code in this module passes the SilverStripe lint rules (mostly PSR-2)",
"points": 0,
"maximum": 10
}
"good_code_coverage": {
"description": "Has a \"good\" level of code coverage (greater than 40%, requires slug)",
"points": 5,
"maximum": 5
},
"has_code_of_conduct_file": {
"description": "Has a code of conduct file",
"points": 2,
"maximum": 2
},
"coding_standards": {
"description": "The PHP code in this module passes the SilverStripe lint rules (mostly PSR-2)",
"points": 0,
"maximum": 10
}
}
```

Expand Down Expand Up @@ -100,7 +101,6 @@ it passes.

Please note the following caveats/gotchas/todos:

* Code coverage is currently only checked via [Codecov.io](https://codecov.io), todo: add Scrutinizer as well
* Code repositories must exist on GitHub for external API checks to work

## Thanks!
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -4,6 +4,7 @@
"type": "library",
"require": {
"symfony/console": "~3.0|~4.0",
"symfony/finder": "~3.0|~4.0",
"symfony/yaml": "~3.0|~4.0",
"guzzlehttp/guzzle": "^6"
},
Expand Down
43 changes: 43 additions & 0 deletions src/Check/AbstractFileCheck.php
@@ -0,0 +1,43 @@
<?php

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;
use Symfony\Component\Finder\Finder;

/**
* Provides a base class for checks that rely on filesystem checks to extend, giving access to a
* Symfony finder component
*/
abstract class AbstractFileCheck extends Check
{
/**
* @var Finder
*/
protected $finder;

/**
* Get the file finder component
*
* @return Finder
*/
public function getFinder()
{
if (!$this->finder) {
$this->finder = new Finder();
}
return $this->finder;
}

/**
* Set the finder component to use
*
* @param Finder $finder
* @return $this
*/
public function setFinder(Finder $finder)
{
$this->finder = $finder;
return $this;
}
}
16 changes: 7 additions & 9 deletions src/Check/CodeOrSrcFolderCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class CodeOrSrcFolderCheck extends Check
class CodeOrSrcFolderCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,11 +16,11 @@ public function getDescription()

public function run()
{
$options = ['code', 'src'];
foreach ($options as $folder) {
if (file_exists($this->getSuite()->getModuleRoot() . '/' . $folder)) {
$this->setSuccessful(true);
}
}
$files = $this->getFinder()
->directories()
->in($this->getSuite()->getModuleRoot())
->name('/code|src$/');

$this->setSuccessful(count($files) > 0);
}
}
24 changes: 7 additions & 17 deletions src/Check/ContributingFileCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class ContributingFileCheck extends Check
class ContributingFileCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,19 +16,11 @@ public function getDescription()

public function run()
{
$options = [
'contributing',
'CONTRIBUTING',
'contributing.md',
'CONTRIBUTING.md',
'contributing.txt',
'CONTRIBUTING.txt',
];
foreach ($options as $filename) {
if (file_exists($this->getSuite()->getModuleRoot() . '/' . $filename)) {
$this->setSuccessful(true);
break;
}
}
$files = $this->getFinder()
->files()
->in($this->getSuite()->getModuleRoot())
->name('/contributing(?:\.md|\.txt)?$/i');

$this->setSuccessful(count($files) > 0);
}
}
13 changes: 7 additions & 6 deletions src/Check/DocumentationCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class DocumentationCheck extends Check
class DocumentationCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,8 +16,11 @@ public function getDescription()

public function run()
{
if (file_exists($this->getSuite()->getModuleRoot() . '/docs')) {
$this->setSuccessful(true);
}
$files = $this->getFinder()
->directories()
->in($this->getSuite()->getModuleRoot())
->name('/^docs?$/');

$this->setSuccessful(count($files) > 0);
}
}
14 changes: 8 additions & 6 deletions src/Check/EditorConfigFileCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class EditorConfigFileCheck extends Check
class EditorConfigFileCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,8 +16,12 @@ public function getDescription()

public function run()
{
if (file_exists($this->getSuite()->getModuleRoot() . '/.editorconfig')) {
$this->setSuccessful(true);
}
$files = $this->getFinder()
->files()
->ignoreDotFiles(false)
->in($this->getSuite()->getModuleRoot())
->name('.editorconfig');

$this->setSuccessful(count($files) > 0);
}
}
14 changes: 8 additions & 6 deletions src/Check/GitAttributesFileCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class GitAttributesFileCheck extends Check
class GitAttributesFileCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,8 +16,12 @@ public function getDescription()

public function run()
{
if (file_exists($this->getSuite()->getModuleRoot() . '/.gitattributes')) {
$this->setSuccessful(true);
}
$files = $this->getFinder()
->files()
->ignoreDotFiles(false)
->in($this->getSuite()->getModuleRoot())
->name('.gitattributes');

$this->setSuccessful(count($files) > 0);
}
}
17 changes: 7 additions & 10 deletions src/Check/LicenseCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class LicenseCheck extends Check
class LicenseCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,12 +16,11 @@ public function getDescription()

public function run()
{
$options = ['license', 'LICENSE', 'license.md', 'LICENSE.md', 'license.txt', 'LICENSE.txt'];
foreach ($options as $filename) {
if (file_exists($this->getSuite()->getModuleRoot() . '/' . $filename)) {
$this->setSuccessful(true);
break;
}
}
$files = $this->getFinder()
->files()
->in($this->getSuite()->getModuleRoot())
->name('/license(?:\.md|\.txt)?$/i');

$this->setSuccessful(count($files) > 0);
}
}
17 changes: 7 additions & 10 deletions src/Check/ReadmeCheck.php
Expand Up @@ -2,9 +2,7 @@

namespace SilverStripe\ModuleRatings\Check;

use SilverStripe\ModuleRatings\Check;

class ReadmeCheck extends Check
class ReadmeCheck extends AbstractFileCheck
{
public function getKey()
{
Expand All @@ -18,12 +16,11 @@ public function getDescription()

public function run()
{
$options = ['readme', 'README', 'readme.md', 'README.md', 'readme.txt', 'README.txt'];
foreach ($options as $filename) {
if (file_exists($this->getSuite()->getModuleRoot() . '/' . $filename)) {
$this->setSuccessful(true);
break;
}
}
$files = $this->getFinder()
->files()
->in($this->getSuite()->getModuleRoot())
->name('/readme(?:\.md|\.txt)?$/i');

$this->setSuccessful(count($files) > 0);
}
}

0 comments on commit 7847da4

Please sign in to comment.