-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fixes #35: Removendo contantes de configuração. #37
base: master
Are you sure you want to change the base?
Conversation
Foi removido as contantes que tinha caminhos de pastas fisicos e no seu lugar foi adicionado na AppFactory as namespace hardcoded, gerando um debito tecnico, mas removendo essas contantes.
src/Factory/AppFactory.php
Outdated
throw new Exception($e->getMessage()); | ||
} | ||
$class = get_class($objeto); | ||
$classShortName = (new \ReflectionClass($objeto))->getShortName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no caso dessas ReflectionClass a função vai pegar o nome da classe ao invés de precisar fazer um require_once ?
src/Factory/AppFactory.php
Outdated
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
$class = get_class($objeto); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya don't need to get the name of class, just use ReflectionObject
instead.
src/Factory/AppFactory.php
Outdated
$class = get_class($objeto); | ||
$classShortName = (new \ReflectionClass($objeto))->getShortName(); | ||
|
||
$classDAO = '\\PseudoORM\\DAO\\' . $classShortName . 'DAO'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should a DI be used instead?
src/Factory/AppFactory.php
Outdated
: 'Generic' | ||
; | ||
|
||
$repository = '\\PseudoORM\\DAO\\' . $entityName . 'DAO'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repositories should be configured in some kind of mapping file — xml
? —
@@ -33,17 +32,18 @@ public static function getFactory() | |||
|
|||
public static function getRepository(EntidadeBase $objeto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it static?
src/Factory/AppFactory.php
Outdated
@@ -2,7 +2,6 @@ | |||
namespace PseudoORM\Factory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sth?
src/Factory/AppFactory.php
Outdated
|
||
$repository = '\\PseudoORM\\DAO\\' . $entityName . 'DAO'; | ||
|
||
return new $repository($class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if $repository
isn't a valid class?
src/Factory/AppFactory.php
Outdated
|
||
$classDAO = '\\PseudoORM\\DAO\\' . $classShortName . 'DAO'; | ||
|
||
$entityName = class_exists($classDAO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if my repository is an anonymous class?
@@ -14,10 +14,6 @@ define('ENCODING', "SET NAMES 'utf8';"); | |||
define("DB_DSN", "pgsql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME.";"); | |||
define("SHOW_SQL_ERROR", PDO::ERRMODE_EXCEPTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mark this constants to be removed in the future as well? @todo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marquei como @todo
Pelo o que eu pude ler
Considere que cada um desses passo poderia ser melhor escrito/testado isoladamente. Nota: Você pode ter um facade englobando toda essa lógica. /cc @jackmakiyama |
Com certeza, o projeto é bem legado, a ideia era dar uma normalizada pra entrar num ciclo de refatoração. Essa factory eu penso que pode ser removida e trabalhar melhor com composição. Veja um exemplo onde uma normalização iria facilitar na refatoração aqui. |
@malukenho e @jackmakiyama dei uma refatorada no método
Acho que o próximo passo é dar uma refatorada na classe de DAO, ela está fazendo muito mais do que deveria. |
…ntes, removendo parâmetro booleano
IMHO, deve ser instanciado provavelmente. Se preciso, fica a cargo do cliente usar algum tipo de service manager, ou afim. |
{ | ||
$script = $this->geraScriptDeCriacaoDoBancoDeDados($creator); | ||
try { | ||
$dbh = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Que tal passar essa instancia do PDO
via parametro?
public function criaBancoDeDados(IDatabaseCreator $creator) | ||
{ | ||
$script = $this->geraScriptDeCriacaoDoBancoDeDados($creator); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the try
, let it fail instead.
*/ | ||
public function generate(IDataBaseCreator $creator, $create = false); | ||
public function geraScriptDeCriacaoDoBancoDeDados(IDataBaseCreator $creator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English or Portuguese? let's avoid mix languages in here.
|
||
public function getClassShortName() | ||
{ | ||
return (new \ReflectionClass($this))->getShortName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about proxy this ReflectionClass
?
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL EOF
@@ -224,20 +224,21 @@ private function bindArrayValue(\PDOStatement $query, $array, $typeArray = false | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function generate(IDataBaseCreator $creator, $create = false) | |||
public function geraScriptDeCriacaoDoBancoDeDados(IDatabaseCreator $creator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this method be removed? it doesn't do too much now...
@@ -44,8 +44,12 @@ public function insert(EntidadeBase $entidade); | |||
public function update(EntidadeBase $entidade); | |||
|
|||
/** | |||
* Gera script de criação do banco de dados e permite a criação automatica. | |||
* @param bolean $create True to create database automatically | False To print script in screen | |||
* Retorna script de criação do banco de dados. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return
?
/** | ||
* Cria banco de dados | ||
*/ | ||
public function criaBancoDeDados(IDataBaseCreator $creator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return void
?
@@ -17,6 +17,16 @@ class EntidadeBase | |||
} | |||
} | |||
} | |||
|
|||
public function getClassShortName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc?
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
$repository = '\\PseudoORM\\DAO\\' . $objeto->getClassShortName() . 'DAO'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be in a config/map instead?
Apenas como registro do que o @malukenho falou no Telegram: Não tem porque dá merge em uma PR sem ter "terminado" ou deixar pra depois fazer melhor. Temos algumas boas razões pra isso:
|
Foi removido as contantes que tinha caminhos de pastas fisicos e no seu
lugar foi adicionado na AppFactory as namespace hardcoded, gerando um
debito tecnico, mas removendo essas contantes.