Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/View/Front/default/search/index.php (1 issue)

Labels
Severity
1
<?php
2
3
use Ffcms\Core\Helper\Type\Any;
4
use Ffcms\Templex\Url\Url;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Url. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
6
/** @var \Ffcms\Templex\Template\Template $this */
7
/** @var \Apps\Model\Front\Search\EntitySearchMain $model */
8
/** @var string $query */
9
10
$query = $this->e($query);
11
$this->layout('_layouts/default', [
12
    'title' => __('Search: %query%', ['query' => $query]),
13
    'breadcrumbs' => [
14
        Url::to('/') => __('Home'),
15
        __('Search')
16
    ],
17
    'query' => $query
18
]);
19
?>
20
<?php $this->start('body') ?>
21
<h1><?= __('Search query: %query%', ['query' => $query]) ?></h1>
22
<hr />
23
24
<form method="GET" action="<?= Url::to('search/index') ?>" class="form-inline mb-2">
25
    <div class="form-group col-md-9">
26
        <label for="search-field" class="sr-only">Query</label>
27
        <input name="query" type="text" class="form-control col-md" id="search-field" value="<?= $query ?>" maxlength="100">
28
    </div>
29
    <button type="submit" class="btn btn-primary col-md"><?= __('Search') ?></button>
30
</form>
31
32
<?php
33
/** @var \Apps\Model\Front\Search\AbstractSearchResult[] $results */
34
$results = $model->getRelevanceSortedResult();
35
if (!Any::isArray($results) || count($results) < 1) {
36
    echo $this->bootstrap()->alert('warning', __('Matches not founded'));
37
    $this->stop();
38
    return;
39
}
40
?>
41
42
<?php foreach ($results as $item): ?>
43
    <div class="row mt-1">
44
        <div class="col-md-12">
45
            <div class="search-result">
46
                <div class="h4">
47
                    <a href="<?= \App::$Alias->baseUrl . $item->getUri() ?>"><?= $model->highlightText($item->getTitle(), 'span', ['class' => 'search-highlight']) ?></a>
48
                    <small class="float-right text-secondary"><?= $item->getDate() ?></small>
49
                </div>
50
                <small><?= $model->highlightText($item->getSnippet(), 'span', ['class' => 'search-highlight']) ?>...</small>
51
            </div>
52
        </div>
53
    </div>
54
    <hr class="pretty" />
55
<?php endforeach; ?>
56
57
<?php $this->stop() ?>
58