Completed
Push — master ( 1dc1a5...f8d9f6 )
by Anton
10s
created

examples/SiteSearchPinger/index.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Example of usage Yandex\SiteSearchPinger package
4
 *
5
 * @author   Anton Shevchuk
6
 * @created  07.08.13 10:32
7
 */
8
9
use Yandex\SiteSearchPinger\SiteSearchPinger;
10
use Yandex\SiteSearchPinger\Exception\SiteSearchPingerException;
11
use Yandex\Common\Exception\YandexException as YandexException;
12
13
?>
14
<!doctype html>
15
<html lang="en-US">
16
<head>
17
    <meta charset="UTF-8">
18
    <title>Yandex PHP Library: Pinger Demo</title>
19
    <link rel="stylesheet" href="//yandex.st/bootstrap/3.0.0/css/bootstrap.min.css">
20
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
21
    <link rel="stylesheet" href="/examples/Disk/css/style.css">
22
</head>
23
<body>
24
<div class="container">
25
    <div class="jumbotron">
26
        <h2><span class="glyphicon glyphicon-search"></span> Пример работы с Яндекс Пингером</h2>
27
    </div>
28
    <div class="col-md-8">
29
        <ol class="breadcrumb">
30
            <li><a href="/examples">Examples</a></li>
31
            <li class="active">SiteSearchPinger</li>
32
        </ol>
33
        <?php
34
        try {
35
36
            $settings = require_once '../settings.php';
37
            $pinger = new SiteSearchPinger();
38
39 View Code Duplication
            if (!isset($settings["pinger"]["key"]) || !$settings["pinger"]["key"]) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
                throw new SiteSearchPingerException('Empty pinger key');
41
            }
42 View Code Duplication
            if (!isset($settings["pinger"]["login"]) || !$settings["pinger"]["login"]) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
                throw new SiteSearchPingerException('Empty pinger key');
44
            }
45 View Code Duplication
            if (!isset($settings["pinger"]["searchId"]) || !$settings["pinger"]["searchId"]) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                throw new SiteSearchPingerException('Empty pinger key');
47
            }
48
49
            $pinger->key = $settings["pinger"]["key"];
50
            $pinger->login = $settings["pinger"]["login"];
51
            $pinger->searchId = $settings["pinger"]["searchId"];
52
53
            $url = [
54
                "http://anton.shevchuk.name/php/php-development-environment-under-macos/",
55
                "http://anton.shevchuk.name/php/php-framework-bluz-update/",
56
                "http://ya.ru",
57
                "http://yandex.ru",
58
                "yaru",
59
                "yarus",
60
            ];
61
62
            $added = $pinger->ping($url);
63
64
            echo "OK. " . $added . " from " . sizeof($url) . " urls was added to queue<br/>";
65
66
            if (sizeof($pinger->invalidUrls)) {
67
                echo "Invalid Urls:" . "<br/>";
68
                foreach ($pinger->invalidUrls as $url => $reason) {
69
                    echo $url . " - " . $reason . "<br/>";
70
                }
71
            }
72
        } catch (SiteSearchPingerException $e) {
73
            echo "Site Search Pinger Exception:<br/>";
74
            echo nl2br($e->getMessage());
75
        } catch (YandexException $e) {
76
            echo "Yandex Library Exception:<br/>";
77
            echo nl2br($e->getMessage());
78
        } catch (\Exception $e) {
79
            echo get_class($e) . "<br/>";
80
            echo nl2br($e->getMessage());
81
        }
82
        ?>
83
    </div>
84
</div>
85
</body>
86
</html>
87