Skip to content

Conversation

@jackmakiyama
Copy link
Member

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.

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.
throw new Exception($e->getMessage());
}
$class = get_class($objeto);
$classShortName = (new \ReflectionClass($objeto))->getShortName();
Copy link
Member

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 ?

} catch (Exception $e) {
throw new Exception($e->getMessage());
}
$class = get_class($objeto);

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.

$class = get_class($objeto);
$classShortName = (new \ReflectionClass($objeto))->getShortName();

$classDAO = '\\PseudoORM\\DAO\\' . $classShortName . 'DAO';

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?

: 'Generic'
;

$repository = '\\PseudoORM\\DAO\\' . $entityName . 'DAO';

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? —

return self::$instance;
}

public static function getRepository(EntidadeBase $objeto)

Choose a reason for hiding this comment

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

Return type?

Choose a reason for hiding this comment

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

Why is it static?

@@ -1,8 +1,7 @@
<?php
namespace PseudoORM\Factory;

Choose a reason for hiding this comment

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

sth?


$repository = '\\PseudoORM\\DAO\\' . $entityName . 'DAO';

return new $repository($class);

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?


$classDAO = '\\PseudoORM\\DAO\\' . $classShortName . 'DAO';

$entityName = class_exists($classDAO)

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?

define("SCHEMA", '');
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);

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 ?

Copy link
Member

Choose a reason for hiding this comment

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

marquei como @todo

@malukenho
Copy link

Pelo o que eu pude ler getRepository está fazendo muito mais do que deveria.

  • Pega dados da entidade
  • Resolve mapa entre entidade e repositório
  • Instancia repositório com metadados — $class?
  • Retorna instancia de determinado repositório

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

@jackmakiyama
Copy link
Member Author

Pelo o que eu pude ler getRepository está fazendo muito mais do que deveria.

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.

@EvandroMohr
Copy link
Member

@malukenho e @jackmakiyama dei uma refatorada no método getRepository separando um pouco mais as responsabilidades.

  • Classes anônimas não são suportadas ainda, quem sabe mais pra frente.
  • A chamada estática é apenas conveniência, nada impede que seja instanciada ou mesmo chamada por um singleton. Inclusive há traços de um singleton antigo que ainda permanece na classe por falta de direcionamento de como isso vai ficar. Não decidimos ainda.

Acho que o próximo passo é dar uma refatorada na classe de DAO, ela está fazendo muito mais do que deveria.

@malukenho
Copy link

A chamada estática é apenas conveniência, nada impede que seja instanciada ou mesmo chamada por um singleton. Inclusive há traços de um singleton antigo que ainda permanece na classe por falta de direcionamento de como isso vai ficar. Não decidimos ainda.

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 ));

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 {

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.

* Retorna script de criação do banco de dados.
*/
public function generate(IDataBaseCreator $creator, $create = false);
public function geraScriptDeCriacaoDoBancoDeDados(IDataBaseCreator $creator);

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();

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?

}
}

}

Choose a reason for hiding this comment

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

EOL EOF

* {@inheritDoc}
*/
public function generate(IDataBaseCreator $creator, $create = false)
public function geraScriptDeCriacaoDoBancoDeDados(IDatabaseCreator $creator)

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...

/**
* 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.

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);

Choose a reason for hiding this comment

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

@return void?

}
}

public function getClassShortName()

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';

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?

@jackmakiyama
Copy link
Member Author

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:

  1. Se trata de um projeto educacional, não tendo necessidade de atender a clientes, PO, sprints, etc... Então, a PR pode esperar até que esteja 100% para ser integrada a base de código principal.

  2. Justamente por se tratar de um projeto educational, a liberdade de experimentar/comentar/compartilhar/etc... deve ser exaltada e discutida excesivamente até que todos entrem em um minimo acordo, ou alguma das partes cedam

  3. Uma contra PR pode ser feita ad hoc como uma forma opcional a essa questão de fazer "micro" PRs

  4. "Tá passando nos testes" não quer dizer nada $this->assertTrue(true); sempre passa, e não testa nada.

  5. Ainda falta o minimo de ajustes em CS
    Bom, nada ha se levar a sério, é só o que eu penso sobre o merge precoce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants