Code Duplication    Length = 15-16 lines in 2 locations

src/allejo/stakx/Logger.php 1 location

@@ 141-155 (lines=15) @@
138
     *
139
     * @return string
140
     */
141
    private function interpolate($message, array $context)
142
    {
143
        // build a replacement array with braces around the context keys
144
        $replace = array();
145
        foreach ($context as $key => $val)
146
        {
147
            if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')))
148
            {
149
                $replace[sprintf('{%s}', $key)] = $val;
150
            }
151
        }
152
153
        // interpolate replacement values into the message and return
154
        return strtr($message, $replace);
155
    }
156
}
157

src/allejo/stakx/Utilities/StrUtils.php 1 location

@@ 22-37 (lines=16) @@
19
     *
20
     * @return string
21
     */
22
    public static function interpolate($message, array $context)
23
    {
24
        // build a replacement array with braces around the context keys
25
        $replace = [];
26
27
        foreach ($context as $key => $val)
28
        {
29
            if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')))
30
            {
31
                $replace[sprintf('{%s}', $key)] = $val;
32
            }
33
        }
34
35
        // interpolate replacement values into the message and return
36
        return strtr($message, $replace);
37
    }
38
39
    /**
40
     * Check if an object can be casted into a string.