Issues (21)

example/find_example.php (3 issues)

1
<?php
2
3
require 'db_config.php';
4
require '../vendor/autoload.php';
5
6
require 'Models/User.php';
7
require 'Models/Address.php';
8
require 'Models/Company.php';
9
10
use Example\Models\Address;
11
use Example\Models\Company;
12
use Example\Models\User;
13
14
/*
15
 * MODEL
16
 */
17
echo "<h1>User Model</h1>";
18
$user = new User();
19
var_dump($user);
20
21
echo "<h1>Find By Id</h1>";
22
$user = (new User())->findById(4);
23
var_dump($user->data(), [$user->first_name, $user->full_name]);
0 ignored issues
show
Bug Best Practice introduced by
The property first_name does not exist on CoffeeCode\DataLayer\DataLayer. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property full_name does not exist on CoffeeCode\DataLayer\DataLayer. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
25
/**
26
 * FIND EXAMPLE
27
 */
28
echo "<h1>Find</h1>";
29
//$result = $user->find()->fetch(true);
30
//$result = $user->find()->group("genre")->fetch(true);
31
//$result = $user->find()->limit(4)->fetch(true);
32
//$result = $user->find()->limit(2)->offset(2)->fetch(true);
33
//$result = $user->find()->limit(4)->offset(2)->order("id DESC")->fetch(true);
34
//$result = $user->find()->limit(2)->offset(2)->order("RAND()")->fetch(true);
35
36
$result = $user->find()->limit(1)->fetch(true);
37
$totalUsers = $user->find()->count();
38
echo "<h2>{$totalUsers} cadastros!</h2>";
39
40
if ($result) {
41
    foreach ($result as $user) {
42
        var_dump($user->data());
43
    }
44
} else {
45
    echo "<h2>Not Users</h2>";
46
}
47
48
echo "<h1>Secure Params</h1>";
49
$params = http_build_query(["name" => "UpInside"]);
50
$company = (new Company())->find("name = :name", $params);
51
var_dump($company->fetch()->data());
52
53
54
echo "<h1>Join</h1>";
55
56
$addresses = new Address();
57
$address = $addresses->findById(1);
58
$address->getUser();
0 ignored issues
show
The method getUser() does not exist on CoffeeCode\DataLayer\DataLayer. It seems like you code against a sub-type of CoffeeCode\DataLayer\DataLayer such as Example\Models\Address. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
$address->/** @scrutinizer ignore-call */ 
59
          getUser();
Loading history...
59
60
var_dump($address->data());
61
62
echo "<h1>Table Columns</h1>";
63
64
var_dump($user->columns()); //object
65
var_dump($user->columns(PDO::FETCH_COLUMN));