Code Duplication    Length = 29-30 lines in 2 locations

src/PhpSpreadsheet/Calculation/Engineering.php 2 locations

@@ 1200-1229 (lines=30) @@
1197
     *                                If places is negative, BIN2HEX returns the #NUM! error value.
1198
     * @return    string
1199
     */
1200
    public static function BINTOHEX($x, $places = null)
1201
    {
1202
        $x = Functions::flattenSingleValue($x);
1203
        $places = Functions::flattenSingleValue($places);
1204
1205
        // Argument X
1206
        if (is_bool($x)) {
1207
            if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
1208
                $x = (int)$x;
1209
            } else {
1210
                return Functions::VALUE();
1211
            }
1212
        }
1213
        if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
1214
            $x = floor($x);
1215
        }
1216
        $x = (string)$x;
1217
        if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1218
            return Functions::NAN();
1219
        }
1220
        if (strlen($x) > 10) {
1221
            return Functions::NAN();
1222
        } elseif (strlen($x) == 10) {
1223
            //    Two's Complement
1224
            return str_repeat('F', 8) . substr(strtoupper(dechex(bindec(substr($x, -9)))), -2);
1225
        }
1226
        $hexVal = (string)strtoupper(dechex(bindec($x)));
1227
1228
        return self::nbrConversionFormat($hexVal, $places);
1229
    }
1230
1231
1232
    /**
@@ 1256-1284 (lines=29) @@
1253
     *                                If places is negative, BIN2OCT returns the #NUM! error value.
1254
     * @return    string
1255
     */
1256
    public static function BINTOOCT($x, $places = null)
1257
    {
1258
        $x = Functions::flattenSingleValue($x);
1259
        $places = Functions::flattenSingleValue($places);
1260
1261
        if (is_bool($x)) {
1262
            if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
1263
                $x = (int)$x;
1264
            } else {
1265
                return Functions::VALUE();
1266
            }
1267
        }
1268
        if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
1269
            $x = floor($x);
1270
        }
1271
        $x = (string)$x;
1272
        if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1273
            return Functions::NAN();
1274
        }
1275
        if (strlen($x) > 10) {
1276
            return Functions::NAN();
1277
        } elseif (strlen($x) == 10) {
1278
            //    Two's Complement
1279
            return str_repeat('7', 7) . substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
1280
        }
1281
        $octVal = (string)decoct(bindec($x));
1282
1283
        return self::nbrConversionFormat($octVal, $places);
1284
    }
1285
1286
1287
    /**