Skip to content

Instantly share code, notes, and snippets.

@grogy
Last active August 31, 2016 22:42
Show Gist options
  • Save grogy/1aaaf3683dafa91e30f9aa8f930a6513 to your computer and use it in GitHub Desktop.
Save grogy/1aaaf3683dafa91e30f9aa8f930a6513 to your computer and use it in GitHub Desktop.

Zadání pro lektory

  1. Vem kód,
  2. forkni ho,
  3. přidej 2 chyby.

Pak forky projedu a pospojuju.

Cílem je soubor o ~100 řádcích, tak přidávej metody a třídy!

Přihlášení účastníci ho pak budou muset projít, chyby najít, opravit a odůvodnit proč. Stejný úkol byl použitý pro Java Codecamp

Jaké chyby tam dát?

ANO

  • PHP 5.4+
  • logické myšlení
  • přehlednost
  • budeme učit Symfony, takže i nějaké MVC myšlení
  • SOLID patterns, spíš ty jednodušší
  • něco, co v práci často opravujete a považujete to za obecnou znalost
  • refaktoring

Např. Dependency Injection.

NE

  • překlepy
  • super PHP internals, hashmapy, efektivita atd.
  • super expertní znalosti
  • akademické chytáky ve stylu "hi" + 5, které vám IDE odhladí
  • vůbec ne nic, co dokáže IDE odhalit; netestujeme IDE
  • PHP 7.1, moc zkušené lidi nechceme1
<?php
include __DIR__ . '/../libs/BaseContainer.php';
include __DIR__ . '/../libs/Container.php';
class AbstractAdminController extends FrameworkController
{
/**
* @var Connection
*/
public $connection;
public $exportRepository;
public $c;
// This is a constructor for AbstractAdminController.
public function __construct()
{
$this->connection = Container::get('connection');
$this->exportRepository = Container::get('exportModel');
$this->c = null;
}
public function exportListAction(User $user)
{
if ($user->getId() != 1 || $user->getLogin() != 'admin') {
throw new Exception('Error.');
}
return array(
'exports' => $this->exportRepository->getAllExports((int) $id),
'login_form' => $this->getLoginForm(),
'c' => $this->getCountOfSucccessExports()
);
}
public function exportDefailAction(string $id, User $user)
{
if ($user->getId() != 1 || $user->getLogin() != 'admin') {
throw new Exception('Error.');
}
return [
'exportDetail' => $this->exportRepository->getDetail((int) $id),
'login_form' => $this->getLoginForm()
];
}
public function getLoginForm()
{
$form = new Form;
$form->addText('login');
$form->addPassword('password');
$form->addSubmit('send', 'Send');
return $form;
}
public function getCountOfSucccessExports()
{
$exports = $this->exportRepository->getAllExports();
for ($i = 0; $i < count($exports); $i++) {
if (!empty($exports['id']))
if ($exports['type'] == 'yes')
++$this->c;
}
return $this->c;
}
}
@TomasVotruba
Copy link

Díky, můžeš máznout.

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