Passed
Push — Showing-Posts ( 7edb4f...c0e04f )
by Stone
01:52
created

CategoryModel::getMenu()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
namespace App\Models;
3
4
use Core\Model;
5
6
class CategoryModel extends Model{
7
8
    /**
9
     * get the list of categories and return all the data
10
     * @return array the categories
11
     * @throws \ReflectionException
12
     */
13
    public function getCategories(){
14
        return $this->getResultSet('categories');
15
    }
16
17
    /**
18
     * get all the menu elements from the database
19
     * @return array the categories and access URL
20
     * @throws \ReflectionException
21
     */
22
    public function getMenu(): array
23
    {
24
        $data = [];
25
        //get the categories from database
26
        $categories = $this->getCategories();
27
        foreach ($categories as $category) {
28
            $data += [
29
                $category->category_name => '/category/' . $category->categories_slug
30
            ];
31
        }
32
        return $data;
33
    }
34
}