Skip to content

Commit

Permalink
Merge pull request #38 from LaravelCollective/analysis-8br9A8
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
tshafer committed Dec 5, 2015
2 parents fb4b900 + 0c353e6 commit b6a5aa1
Show file tree
Hide file tree
Showing 41 changed files with 1,577 additions and 1,547 deletions.
21 changes: 11 additions & 10 deletions src/AnnotationFinder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php namespace Collective\Annotations;
<?php

use Illuminate\Contracts\Foundation\Application;
namespace Collective\Annotations;

class AnnotationFinder {
use Illuminate\Contracts\Foundation\Application;

class AnnotationFinder
{
/**
* @var Application
*/
Expand All @@ -12,12 +14,11 @@ class AnnotationFinder {
/**
* @param Application $app
*/
function __construct(Application $app)
public function __construct(Application $app)
{
$this->app = $app;
}


/**
* Determine if the application routes have been scanned.
*
Expand All @@ -35,7 +36,7 @@ public function routesAreScanned()
*/
public function getScannedRoutesPath()
{
return $this->app['path.storage'] . '/framework/routes.scanned.php';
return $this->app['path.storage'].'/framework/routes.scanned.php';
}

/**
Expand All @@ -55,7 +56,7 @@ public function eventsAreScanned()
*/
public function getScannedEventsPath()
{
return $this->app['path.storage'] . '/framework/events.scanned.php';
return $this->app['path.storage'].'/framework/events.scanned.php';
}

/**
Expand All @@ -65,7 +66,7 @@ public function getScannedEventsPath()
*/
public function modelsAreScanned()
{
return $this->app['files']->exists($this->getScannedModelsPath());
return $this->app['files']->exists($this->getScannedModelsPath());
}

/**
Expand All @@ -75,6 +76,6 @@ public function modelsAreScanned()
*/
public function getScannedModelsPath()
{
return $this->app['path.storage'] . '/framework/models.scanned.php';
return $this->app['path.storage'].'/framework/models.scanned.php';
}
}
}
235 changes: 117 additions & 118 deletions src/AnnotationScanner.php
Original file line number Diff line number Diff line change
@@ -1,133 +1,132 @@
<?php namespace Collective\Annotations;
<?php

namespace Collective\Annotations;

use Collective\Annotations\NamespaceToPathConverterTrait;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
use Exception;
use ReflectionClass;
use Symfony\Component\Finder\Finder;

abstract class AnnotationScanner {

abstract class AnnotationScanner
{
use NamespaceToPathConverterTrait;

/**
* Namespaces to check for annotation reader annotation classes.
*
* @var string
*/
protected $namespaces = [];

/**
* The paths to scan for annotations.
*
* @var array
*/
protected $scan = [];

/**
* Create a new scanner instance.
*
* @param array $scan
* @return void
*/
public function __construct(array $scan)
{
$this->scan = $scan;
}

/**
* Create a new scanner instance.
*
* @param array $scan
* @return static
*/
public static function create(array $scan)
{
return new static($scan);
}

/**
* Get all of the ReflectionClass instances in the scan array.
*
* @return array
*/
protected function getClassesToScan()
{
$classes = [];

foreach ($this->scan as $class)
{
try
{
$classes[] = new ReflectionClass($class);
}
catch (Exception $e)
{
//
}
}

return $classes;
}

/**
* Set the classes to scan
*
* @param array $scans
*/
public function setClassesToScan( array $scans )
{
$this->scan = $scans;
}

/**
* Add an annotation namespace for the SimpleAnnotationReader instance.
*
* If the second parameter is null, it will assume the namespace is PSR-4'd
* inside your app folder.
*
* @param string $namespace
* @param string $path
*/
public function addAnnotationNamespace($namespace, $path = null)
{
$this->namespaces[] = $namespace;

return $this->registerAnnotationsPathWithRegistry(
$path ?: $this->getPathFromNamespace( $namespace )
);
}

/**
* Register the annotator files with the annotation registry
*
* @param string $path
* @return $this
*/
public function registerAnnotationsPathWithRegistry( $path )
{
foreach (Finder::create()->files()->in( $path ) as $file)
{
/**
* Namespaces to check for annotation reader annotation classes.
*
* @var string
*/
protected $namespaces = [];

/**
* The paths to scan for annotations.
*
* @var array
*/
protected $scan = [];

/**
* Create a new scanner instance.
*
* @param array $scan
*
* @return void
*/
public function __construct(array $scan)
{
$this->scan = $scan;
}

/**
* Create a new scanner instance.
*
* @param array $scan
*
* @return static
*/
public static function create(array $scan)
{
return new static($scan);
}

/**
* Get all of the ReflectionClass instances in the scan array.
*
* @return array
*/
protected function getClassesToScan()
{
$classes = [];

foreach ($this->scan as $class) {
try {
$classes[] = new ReflectionClass($class);
} catch (Exception $e) {
//
}
}

return $classes;
}

/**
* Set the classes to scan.
*
* @param array $scans
*/
public function setClassesToScan(array $scans)
{
$this->scan = $scans;
}

/**
* Add an annotation namespace for the SimpleAnnotationReader instance.
*
* If the second parameter is null, it will assume the namespace is PSR-4'd
* inside your app folder.
*
* @param string $namespace
* @param string $path
*/
public function addAnnotationNamespace($namespace, $path = null)
{
$this->namespaces[] = $namespace;

return $this->registerAnnotationsPathWithRegistry(
$path ?: $this->getPathFromNamespace($namespace)
);
}

/**
* Register the annotator files with the annotation registry.
*
* @param string $path
*
* @return $this
*/
public function registerAnnotationsPathWithRegistry($path)
{
foreach (Finder::create()->files()->in($path) as $file) {
AnnotationRegistry::registerFile($file->getRealPath());
}

return $this;
}

/**
* Get an annotation reader instance.
*
* @return \Doctrine\Common\Annotations\SimpleAnnotationReader
*/
protected function getReader()
{
$reader = new SimpleAnnotationReader;

foreach ($this->namespaces as $namespace)
$reader->addNamespace($namespace);

return $reader;
}
}

/**
* Get an annotation reader instance.
*
* @return \Doctrine\Common\Annotations\SimpleAnnotationReader
*/
protected function getReader()
{
$reader = new SimpleAnnotationReader();

foreach ($this->namespaces as $namespace) {
$reader->addNamespace($namespace);
}

return $reader;
}
}
Loading

0 comments on commit b6a5aa1

Please sign in to comment.