knasenn /
proj-ramv1
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Aiur18\User; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | use Aiur18\User\HTMLForm\UserLoginForm; |
||
| 8 | use Aiur18\User\HTMLForm\CreateUserForm; |
||
| 9 | use Aiur18\User\HTMLForm\UpdateForm; |
||
| 10 | use Aiur18\Question\Question; |
||
| 11 | use Aiur18\Question\Comment; |
||
| 12 | use Aiur18\getset\getset; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * A sample controller to show how a controller class can be implemented. |
||
| 16 | */ |
||
| 17 | class UserController implements ContainerInjectableInterface |
||
| 18 | { |
||
| 19 | use ContainerInjectableTrait; |
||
| 20 | |||
| 21 | /** Method |
||
| 22 | */ |
||
| 23 | public function listActionGet() : object |
||
| 24 | { |
||
| 25 | $getServer = new getSet(); |
||
| 26 | if ($getServer->getServer('user_id') != null) { |
||
| 27 | $page = $this->di->get("page"); |
||
| 28 | $user = new User(); |
||
| 29 | $user->setDb($this->di->get("dbqb")); |
||
| 30 | |||
| 31 | $page->add("user/view-all", [ |
||
| 32 | "items" => $user->findAll(), |
||
| 33 | ]); |
||
| 34 | |||
| 35 | return $page->render([ |
||
| 36 | "title" => "A collection of usersYO", |
||
| 37 | ]); |
||
| 38 | } else { |
||
| 39 | $this->di->get("response")->redirect("user/login")->send(); |
||
|
0 ignored issues
–
show
|
|||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | /** Method |
||
| 44 | */ |
||
| 45 | public function infoActionGet($id) : object |
||
| 46 | { |
||
| 47 | $getServer = new getSet(); |
||
| 48 | if ($getServer->getServer('user_id') != null) { |
||
| 49 | $page = $this->di->get("page"); |
||
| 50 | $user = new User(); |
||
| 51 | $user->setDb($this->di->get("dbqb")); |
||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | $questions = new Question(); |
||
| 56 | $questions->setDb($this->di->get("dbqb")); |
||
| 57 | |||
| 58 | $comments = new Comment(); |
||
| 59 | $comments->setDb($this->di->get("dbqb")); |
||
| 60 | |||
| 61 | $page->add("user/info", [ |
||
| 62 | "items" => $user->findAll(), |
||
| 63 | "questions" => $questions->findAllWhere("user_id = ?", $id), |
||
| 64 | "comments" => $comments->findAllWhere("user_id = ?", $id), |
||
| 65 | ]); |
||
| 66 | |||
| 67 | return $page->render([ |
||
| 68 | "title" => "A collection of users", |
||
| 69 | ]); |
||
| 70 | } else { |
||
| 71 | $this->di->get("response")->redirect("user/login")->send(); |
||
|
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return object. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
Loading history...
|
|||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | /** Method |
||
| 76 | */ |
||
| 77 | public function loginAction() : object |
||
| 78 | { |
||
| 79 | $page = $this->di->get("page"); |
||
| 80 | $getServer = new getSet(); |
||
| 81 | if ($getServer->getServer('user_id') != null) { |
||
| 82 | $this->di->get("response")->redirect("user/update")->send(); |
||
| 83 | } else { |
||
| 84 | $getServer->logoutSession(); |
||
| 85 | $form = new UserLoginForm($this->di); |
||
| 86 | $form->check(); |
||
| 87 | $content = $form->getHTML(); |
||
| 88 | $login = "<h4>Dont have an account? <a href='create'>Get started</a></h4>"; |
||
| 89 | } |
||
| 90 | |||
| 91 | $page->add("user/login", [ |
||
| 92 | "content" => $content, |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 93 | "login" => $login, |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 94 | ]); |
||
| 95 | |||
| 96 | |||
| 97 | return $page->render([ |
||
| 98 | "title" => "A login page2", |
||
| 99 | ]); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** Method |
||
| 103 | */ |
||
| 104 | public function createAction() : object |
||
| 105 | { |
||
| 106 | $page = $this->di->get("page"); |
||
| 107 | $form = new CreateUserForm($this->di); |
||
| 108 | $form->check(); |
||
| 109 | |||
| 110 | $page->add("user/user", [ |
||
| 111 | "content" => $form->getHTML(), |
||
| 112 | "login" => "" |
||
| 113 | ]); |
||
| 114 | |||
| 115 | return $page->render([ |
||
| 116 | "title" => "A create user page2", |
||
| 117 | ]); |
||
| 118 | } |
||
| 119 | |||
| 120 | |||
| 121 | /** Method |
||
| 122 | */ |
||
| 123 | public function updateAction() : object |
||
| 124 | { |
||
| 125 | $getServer = new getSet(); |
||
| 126 | $id = $getServer->getServer('user_id'); |
||
| 127 | $page = $this->di->get("page"); |
||
| 128 | |||
| 129 | $form = new UpdateForm($this->di, $id); |
||
| 130 | $form->check(); |
||
| 131 | |||
| 132 | $user = new User(); |
||
| 133 | $user->setDb($this->di->get("dbqb")); |
||
| 134 | $userInfo = $user->findAllWhere("id = ?", $id); |
||
| 135 | $avatar = $user->checkAvatar($userInfo[0]->avatar_image); |
||
| 136 | |||
| 137 | $page->add("user/update", [ |
||
| 138 | "form" => $form->getHTML(), |
||
| 139 | "avatar" => $avatar, |
||
| 140 | ]); |
||
| 141 | |||
| 142 | return $page->render([ |
||
| 143 | "title" => "Update an item", |
||
| 144 | ]); |
||
| 145 | } |
||
| 146 | |||
| 147 | /** Method |
||
| 148 | */ |
||
| 149 | public function logoutActionGet() : object |
||
| 150 | { |
||
| 151 | $page = $this->di->get("page"); |
||
|
0 ignored issues
–
show
|
|||
| 152 | |||
| 153 | //temp |
||
| 154 | $user = new User(); |
||
| 155 | $user->logoutSession(); |
||
| 156 | $this->di->get("response")->redirect("user/login")->send(); |
||
|
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return object. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
Loading history...
|
|||
| 157 | } |
||
| 158 | } |
||
| 159 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: