• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / debug / 11867178430

24 Oct 2024 08:51PM UTC coverage: 97.243%. Remained the same
11867178430

push

github

natanfelles
Add comment about breakpoint

529 of 544 relevant lines covered (97.24%)

2.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/SearchEngines.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Debug Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\Debug;
11

12
use InvalidArgumentException;
13

14
/**
15
 * Class SearchEngines.
16
 *
17
 * @package debug
18
 */
19
class SearchEngines
20
{
21
    /**
22
     * @var array<string,string>
23
     */
24
    protected array $engines = [
25
        'ask' => 'https://www.ask.com/web?q=',
26
        'baidu' => 'https://www.baidu.com/s?wd=',
27
        'bing' => 'https://www.bing.com/search?q=',
28
        'duckduckgo' => 'https://duckduckgo.com/?q=',
29
        'google' => 'https://www.google.com/search?q=',
30
        'yahoo' => 'https://search.yahoo.com/search?p=',
31
        'yandex' => 'https://yandex.com/search/?text=',
32
    ];
33
    protected string $current = 'google';
34

35
    public function __construct(?string $current = null)
36
    {
37
        if (isset($current)) {
9✔
38
            $this->setCurrent($current);
1✔
39
        }
40
    }
41

42
    /**
43
     * @return array<string,string>
44
     */
45
    public function getAll() : array
46
    {
47
        return $this->engines;
1✔
48
    }
49

50
    public function add(string $name, string $url) : static
51
    {
52
        $this->engines[$name] = $url;
1✔
53
        return $this;
1✔
54
    }
55

56
    public function getUrl(string $name) : string
57
    {
58
        if (!isset($this->engines[$name])) {
5✔
59
            throw new InvalidArgumentException('Invalid search engine name: ' . $name);
1✔
60
        }
61
        return $this->engines[$name];
5✔
62
    }
63

64
    public function setCurrent(string $name) : static
65
    {
66
        if (!isset($this->engines[$name])) {
2✔
67
            throw new InvalidArgumentException('Invalid search engine name: ' . $name);
1✔
68
        }
69
        $this->current = $name;
1✔
70
        return $this;
1✔
71
    }
72

73
    public function getCurrent() : string
74
    {
75
        return $this->current;
6✔
76
    }
77

78
    public function getCurrentUrl() : string
79
    {
80
        return $this->getUrl($this->getCurrent());
3✔
81
    }
82

83
    public function makeLink(string $query, ?string $name = null) : string
84
    {
85
        $link = isset($name) ? $this->getUrl($name) : $this->getCurrentUrl();
3✔
86
        return $link . \urlencode($query);
3✔
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc