Issues (435)

app/Http/Controllers/BooksController.php (2 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\Books;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Arr;
9
10
class BooksController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function index(Request $request, string $id = '')
16
    {
17
        $book = new Books(['Settings' => $this->settings]);
0 ignored issues
show
The call to Blacklight\Books::__construct() has too many arguments starting with array('Settings' => $this->settings). ( Ignorable by Annotation )

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

17
        $book = /** @scrutinizer ignore-call */ new Books(['Settings' => $this->settings]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
18
19
        $boocats = Category::getChildren(Category::BOOKS_ROOT);
20
21
        $btmp = [];
22
        foreach ($boocats as $bcat) {
23
            $btmp[] =
24
                [
25
                    'id' => $bcat->id,
26
                    'title' => $bcat->title,
27
                ];
28
        }
29
        $category = $request->has('t') ? $request->input('t') : Category::BOOKS_ROOT;
30
        if ($id && \in_array($id, Arr::pluck($btmp, 'title'), false)) {
31
            $cat = Category::query()
32
                ->where('title', $id)
33
                ->where('root_categories_id', '=', Category::BOOKS_ROOT)
34
                ->first(['id']);
35
            $category = $cat !== null ? $cat['id'] : Category::BOOKS_ROOT;
36
        }
37
38
        $catarray = [];
39
        $catarray[] = $category;
40
41
        $ordering = $book->getBookOrdering();
42
        $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
43
44
        $books = [];
45
        $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
46
        $offset = ($page - 1) * config('nntmux.items_per_cover_page');
47
        $rslt = $book->getBookRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions);
0 ignored issues
show
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
48
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
49
        $maxwords = 50;
50
        foreach ($results as $result) {
51
            if (! empty($result->overview)) {
52
                $words = explode(' ', $result->overview);
53
                if (\count($words) > $maxwords) {
54
                    $newwords = \array_slice($words, 0, $maxwords);
55
                    $result->overview = implode(' ', $newwords).'...';
56
                }
57
            }
58
            $books[] = $result;
59
        }
60
61
        $author = ($request->has('author') && ! empty($request->input('author'))) ? stripslashes($request->input('author')) : '';
62
63
        $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
64
65
        $browseby_link = '&title='.$title.'&author='.$author;
66
67
        if ((int) $category === -1) {
68
            $catname = 'All';
69
        } else {
70
            $cdata = Category::find($category);
71
            if ($cdata !== null) {
72
                $catname = $cdata->title;
73
            } else {
74
                $catname = 'All';
75
            }
76
        }
77
78
        // Build order by URLs
79
        $orderByUrls = [];
80
        foreach ($ordering as $ordertype) {
81
            $orderByUrls['orderby'.$ordertype] = url('/Books/'.($id ?: 'All').'?t='.$category.$browseby_link.'&ob='.$ordertype.'&offset=0');
82
        }
83
84
        $this->viewData = array_merge($this->viewData, [
85
            'catlist' => $btmp,
86
            'category' => $category,
87
            'categorytitle' => $id,
88
            'catname' => $catname,
89
            'author' => $author,
90
            'title' => $title,
91
            'resultsadd' => $books,
92
            'results' => $results,
93
            'covgroup' => 'books',
94
            'meta_title' => 'Browse Books',
95
            'meta_keywords' => 'browse,nzb,books,description,details',
96
            'meta_description' => 'Browse for Books',
97
        ], $orderByUrls);
98
99
        return view('books.index', $this->viewData);
100
    }
101
}
102