Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/phpDocumentor/Reflection/File/LocalFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\File;


use phpDocumentor\Reflection\File;

/**
* Represents a local file on the file system.
*/
final class LocalFile implements File
{
/**
* Path to the file.
* @var string
*/
private $path;

/**
* LocalFile constructor.
* @param string $path
*/
public function __construct($path)
{
$this->path = $path;
}

/**
* Returns the content of the file as a string.
*
* @return string
*/
public function getContents()
{
return file_get_contents($this->path);
}

/**
* Returns md5 hash of the file.
*
* @return string
*/
public function md5()
{
return md5_file($this->path);
}

/**
* Returns an relative path to the file.
*
* @return string
*/
public function path()
{
return $this->path;
}
}
37 changes: 15 additions & 22 deletions src/phpDocumentor/Reflection/Php/Factory/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
namespace phpDocumentor\Reflection\Php\Factory;

use InvalidArgumentException;
use phpDocumentor\Reflection\File as FileSystemFile;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Middleware\ChainFactory;
use phpDocumentor\Reflection\Middleware\Middleware;
use phpDocumentor\Reflection\Php\Factory\File\Adapter;
use phpDocumentor\Reflection\Php\Factory\File\CreateCommand;
use phpDocumentor\Reflection\Php\Factory\File\LocalAdapter;
use phpDocumentor\Reflection\Php\File as FileElement;
use phpDocumentor\Reflection\Php\NodesFactory;
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
Expand Down Expand Up @@ -56,17 +55,11 @@ final class File implements ProjectFactoryStrategy
* Initializes the object.
*
* @param NodesFactory $nodesFactory
* @param Adapter $adapter
* @param Middleware[] $middleware
*/
public function __construct(NodesFactory $nodesFactory, Adapter $adapter = null, $middleware = array())
public function __construct(NodesFactory $nodesFactory, $middleware = array())
{
if ($adapter === null) {
$adapter = new LocalAdapter();
}

$this->nodesFactory = $nodesFactory;
$this->adapter = $adapter;

$lastCallable = function ($command) {
return $this->createFile($command);
Expand All @@ -78,20 +71,20 @@ public function __construct(NodesFactory $nodesFactory, Adapter $adapter = null,
/**
* Returns true when the strategy is able to handle the object.
*
* @param string $filePath path to check.
* @param string $file path to check.
* @return boolean
*/
public function matches($filePath)
public function matches($file)
{
return is_string($filePath) && $this->adapter->fileExists($filePath);
return $file instanceof FileSystemFile;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test the interface and not the concrete instance?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the interface, use phpDocumentor\Reflection\File as FileSystemFile;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry :)

}

/**
* Creates an File out of the given object.
* Since an object might contain other objects that need to be converted the $factory is passed so it can be
* used to create nested Elements.
*
* @param string $object path to the file to convert to an File object.
* @param FileSystemFile $object path to the file to convert to an File object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the interface and not the concrete instance?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind :)

* @param StrategyContainer $strategies used to convert nested objects.
* @param Context $context
* @return File
Expand All @@ -107,33 +100,33 @@ public function create($object, StrategyContainer $strategies, Context $context
);
}

$command = new CreateCommand($this->adapter, $object, $strategies);
$command = new CreateCommand($object, $strategies);
$middlewareChain = $this->middlewareChain;

return $middlewareChain($command);
}

/**
* @param $object
* @param StrategyContainer $strategies
* @param CreateCommand $command
* @return FileElement
*/
private function createFile(CreateCommand $command)
{
$code = $this->adapter->getContents($command->getFilePath());
$file = $command->getFile();
$code = $file->getContents();
$nodes = $this->nodesFactory->create($code);
$docBlock = $this->createDocBlock($command->getStrategies(), $code, $nodes);

$file = new FileElement(
$this->adapter->md5($command->getFilePath()),
$this->adapter->path($command->getFilePath()),
$result = new FileElement(
$file->md5(),
$file->path(),
$code,
$docBlock
);

$this->createElements(new Fqsen('\\'), $nodes, $file, $command->getStrategies());
$this->createElements(new Fqsen('\\'), $nodes, $result, $command->getStrategies());

return $file;
return $result;
}

/**
Expand Down
51 changes: 0 additions & 51 deletions src/phpDocumentor/Reflection/Php/Factory/File/Adapter.php

This file was deleted.

45 changes: 13 additions & 32 deletions src/phpDocumentor/Reflection/Php/Factory/File/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace phpDocumentor\Reflection\Php\Factory\File;


use phpDocumentor\Reflection\File;
use phpDocumentor\Reflection\Php\StrategyContainer;

/**
Expand All @@ -21,14 +22,9 @@
final class CreateCommand
{
/**
* @var Adapter
* @var File
*/
private $adapter;

/**
* @var string
*/
private $object;
private $file;

/**
* @var StrategyContainer
Expand All @@ -38,45 +34,30 @@ final class CreateCommand
/**
* Initializes this command.
*
* @param Adapter $adapter
* @param string $object
* @param File $file
* @param StrategyContainer $strategies
*/
public function __construct(Adapter $adapter, $object, StrategyContainer $strategies)
public function __construct(File $file, StrategyContainer $strategies)
{

$this->adapter = $adapter;
$this->object = $object;
$this->file = $file;
$this->strategies = $strategies;
}

/**
* Returns the adapter used by the command handler for this command.
*
* @return Adapter
*/
public function getAdapter()
{
return $this->adapter;
}

/**
* Returns the path of the processed file.
* Returns the strategyContainer in this command context.
*
* @return string
* @return StrategyContainer
*/
public function getFilePath()
public function getStrategies()
{
return $this->object;
return $this->strategies;
}

/**
* Returns the strategyContainer in this command context.
*
* @return StrategyContainer
* @return File
*/
public function getStrategies()
public function getFile()
{
return $this->strategies;
return $this->file;
}
}
Loading