craftResultString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * This file is meant to provide an example of the execution of this package.
4
 *
5
 * @author Mazen Touati <[email protected]>
6
 * @license MIT
7
 */
8
9
require 'vendor/autoload.php';
10
11
use MazenTouati\Simple2wayConfig\S2WConfigFactory;
12
use MazenTouati\NoEmoji\Scrapper;
13
use MazenTouati\NoEmoji\Handler;
14
use MazenTouati\NoEmoji\Prettifier;
15
16
// Initialize the configuration
17
$config = S2WConfigFactory::create(__DIR__ . '/config');
18
19
$viewData = [];
20
21
// Scrapping
22
// ---
23
$viewData['scrape'] = Scrapper::factory($config)->run()->export();
24
25
// Handling
26
// ---
27
$handler = Handler::factory($config)->run();
28
$viewData['handle'] = $handler->export();
29
30
// Testing
31
// ---
32
$viewData['test']  = $handler->testPattern();
33
34
// Prettifier
35
// ---
36
$viewData['Prettifier'] = Prettifier::factory($config)->run()->export();
37
38
// Functions
39
// ---
40
41
/**
42
 * Transform the result array to a meaningful information
43
 *
44
 * @param  string $kind   the data kind eg: scrape...
45
 * @param  bool|string $result export's result
46
 *
47
 * @return string treated information
48
 */
49
function craftResultString(string $kind, $result)
50
{
51
    if ($result === false) {
52
        return ucfirst($kind) . ': <span class="error">Oops ! something went wrong...</span>';
53
    } else {
54
        if (isset($result['count'])) {
55
            $kind = $kind . ' ( ' . $result['count'] . ' Emoji replaced ) ';
56
        }
57
        return ucfirst($kind) . ": <a href='{$result['path']}' target='_blank'>{$result['fileTitle']}</a> <small>[ {$result['size']} Bytes ]</small>";
58
    }
59
}
60
61
?>
62
63
<!DOCTYPE html>
64
<html lang="en">
65
<head>
66
  <meta charset="UTF-8">
67
  <title>No Emoji Pattern generator</title>
68
69
  <style>
70
    body {
71
        color: #222;
72
    }
73
74
    .error {
75
      color: red;
76
    }
77
78
    a {
79
        color: blue;
80
        text-decoration: none;
81
    }
82
83
    small {
84
        color: #888;
85
    }
86
87
    ul {
88
      margin: 0;
89
      padding-left: 18px;
90
      line-height: 1.5rem;
91
    }
92
93
    footer {
94
      padding: 2rem 0;
95
    }
96
  </style>
97
</head>
98
<body>
99
  <h2>No Emoji Pattern generator</h2>
100
  <hr>
101
  The execution generated the following files :
102
  <ul>
103
    <?php
104
      foreach ($viewData as $kind => $result) {
105
          echo '<li>'. craftResultString($kind, $result) .'</li>';
106
      }
107
    ?>
108
  </ul>
109
110
  <footer>
111
    Copyright <a href="https://mazentouati.github.io">Mazen Touati</a> - MIT License @2019
112
  </footer>
113
</body>
114
</html>
115