Code Duplication    Length = 32-34 lines in 2 locations

src/PhpSpreadsheet/Calculation/Statistical.php 2 locations

@@ 3170-3203 (lines=34) @@
3167
     *
3168
     * @return float
3169
     */
3170
    public static function STDEV(...$args)
3171
    {
3172
        $aArgs = Functions::flattenArrayIndexed($args);
3173
3174
        // Return value
3175
        $returnValue = null;
3176
3177
        $aMean = self::AVERAGE($aArgs);
3178
        if (!is_null($aMean)) {
3179
            $aCount = -1;
3180
            foreach ($aArgs as $k => $arg) {
3181
                if ((is_bool($arg)) &&
3182
                    ((!Functions::isCellValue($k)) || (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE))) {
3183
                    $arg = (int) $arg;
3184
                }
3185
                // Is it a numeric value?
3186
                if ((is_numeric($arg)) && (!is_string($arg))) {
3187
                    if (is_null($returnValue)) {
3188
                        $returnValue = pow(($arg - $aMean), 2);
3189
                    } else {
3190
                        $returnValue += pow(($arg - $aMean), 2);
3191
                    }
3192
                    ++$aCount;
3193
                }
3194
            }
3195
3196
            // Return
3197
            if (($aCount > 0) && ($returnValue >= 0)) {
3198
                return sqrt($returnValue / $aCount);
3199
            }
3200
        }
3201
3202
        return Functions::DIV0();
3203
    }
3204
3205
    /**
3206
     * STDEVA.
@@ 3271-3302 (lines=32) @@
3268
     *
3269
     * @return float
3270
     */
3271
    public static function STDEVP(...$args)
3272
    {
3273
        $aArgs = Functions::flattenArrayIndexed($args);
3274
3275
        $returnValue = null;
3276
3277
        $aMean = self::AVERAGE($aArgs);
3278
        if (!is_null($aMean)) {
3279
            $aCount = 0;
3280
            foreach ($aArgs as $k => $arg) {
3281
                if ((is_bool($arg)) &&
3282
                    ((!Functions::isCellValue($k)) || (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE))) {
3283
                    $arg = (int) $arg;
3284
                }
3285
                // Is it a numeric value?
3286
                if ((is_numeric($arg)) && (!is_string($arg))) {
3287
                    if (is_null($returnValue)) {
3288
                        $returnValue = pow(($arg - $aMean), 2);
3289
                    } else {
3290
                        $returnValue += pow(($arg - $aMean), 2);
3291
                    }
3292
                    ++$aCount;
3293
                }
3294
            }
3295
3296
            if (($aCount > 0) && ($returnValue >= 0)) {
3297
                return sqrt($returnValue / $aCount);
3298
            }
3299
        }
3300
3301
        return Functions::DIV0();
3302
    }
3303
3304
    /**
3305
     * STDEVPA.