Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Config #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/Padawan/Domain/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@
namespace Padawan\Domain;

use Padawan\Domain\Project\Index;
use Padawan\Domain\Project\Config;

class Project
{
private $index;
private $rootFolder;
private $config;
private $plugins = [];

public function __construct(Index $index, $rootFolder = "")
{
$this->index = $index;
$this->rootFolder = $rootFolder;
$this->config = Config::default();
}

/**
* @return Project
*/
public static function withConfig(
Index $index,
$rootFolder,
Config $config
) {
$self = new static($index, $rootFolder);
$self->config = $config;
return $self;
Copy link

@greg0ire greg0ire Jul 25, 2016

Choose a reason for hiding this comment

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

Why not have just one constructor, with the following signature : public function __construct(Index $index, $rootFolder = "", Config $config = null). If $config is null, it can be initialized to Config::default(), right?

Copy link
Member Author

Choose a reason for hiding this comment

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

it looks more elegant with named factories

Choose a reason for hiding this comment

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

I'm not familiar with them (apart from the very ancient time where I learnt C++ and there were several possible constructors), but I guess it's something that might indeed come in handy if you don't want to remember the order of the 1878739 constructor arguments…

}
public function getRootFolder()
{
Expand Down
59 changes: 59 additions & 0 deletions src/Padawan/Domain/Project/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Padawan\Domain\Project;

/**
* Class Config
*/
class Config
{
public function __construct(
$phpVersion,
$plugins,
$excludedDirs,
$cacheDir
) {
$this->_phpVersion = $phpVersion;
$this->_plugins = $plugins;
$this->_excludedDirs = $excludedDirs;
$this->_cacheDir = $cacheDir;
}

/**
* @return Config
*/
public static function default()
{
return new static(
"5.6",
[],
[],
".padawan"
);
}

public function phpVersion()
{
return $this->_phpVersion;
}

public function plugins()
{
return $this->_plugins;
}

public function excludedDirs()
{
return $this->_excludedDirs;
}

public function cacheDir()
{
return $this->_cacheDir;
}

private $_phpVersion;
private $_plugins;
private $_excludedDirs;
private $_cacheDir;
}