Luhn algorithm

@param string|array $check Value to check.
@return bool Success
@see https://en.wikipedia.org/wiki/Luhn_algorithm
488159
public static function luhn($check)
    {
        if (!is_scalar($check) || (int)$check === 0) {
            return false;
        }
        $sum = 0;
        $length = strlen($check);

        for ($position = 1 - ($length % 2); $position < $length; $position += 2) {
            $sum += $check[$position];
        }

        for ($position = ($length % 2); $position < $length; $position += 2) {
            $number = (int)$check[$position] * 2;
            $sum += ($number < 10) ? $number : $number - 9;
        }

        return ($sum % 10 === 0);
    }
380959
protected function check($name, $check = '')
    {
        if (!isset($this->keyMap[$name])) {
            return false;
        }
        return ($this->keyMap[$name]['checksum'] === $this->generateNewChecksum($check));
    }
174668
public static function isAboveMinWidth($check, $width)
    {
        // Non-file uploads also mean the height is too big
        if (!isset($check['tmp_name']) || !strlen($check['tmp_name'])) {
            return false;
        }
        list($imgWidth) = getimagesize($check['tmp_name']);

        return $width > 0 && $imgWidth >= $width;
    }
531543
public function checkIntegrity($check=true,$schema='')
	{
		if($schema==='')
			$schema=$this->getDefaultSchema();
		$mode=$check ? 'ENABLE' : 'DISABLE';
		foreach($this->getTableNames($schema) as $table)
		{
			$constraints=$this->getDbConnection()
				->createCommand("SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME=:t AND OWNER=:o")
				->queryColumn(array(':t'=>$table,':o'=>$schema));
			foreach($constraints as $constraint)
				$this->getDbConnection()
					->createCommand("ALTER TABLE \"{$schema}\".\"{$table}\" {$mode} CONSTRAINT \"{$constraint}\"")
					->execute();
		}
	}
1270965
protected function _createcronjobs($check = false) {
		$this->out(__d('cake_installer', 'Creating cron jobs'));
		$this->hr();

		$result = true;
		if ($this->InstallerCheck->isOsWindows()) {
			$this->out(__d('cake_installer', 'Server OS is Windows. Creating cron jobs skipped.'));

			return $result;
		}

		$resultCheck = $this->InstallerCheck->checkCronJobsExists();
		if ($resultCheck) {
			if ($check) {
				$this->out('<success>' . __d('cake_installer', 'This action has already been successfully completed. Skipped.') . '</success>');

				return true;
			} elseif ($this->useActionNotify) {
				if (!$this->_checkSure(__d('cake_installer', 'All cron jobs exists. Rewrite?'), 'n')) {
					return true;
				}
			}
		}

		$cronjobsList = $this->ConfigInstaller->getListCronJobsCreation();
		if (empty($cronjobsList)) {
			$this->out('<info>' . __d('cake_installer', 'List of cron jobs is empty') . '</info>');

			return true;
		}

		$apacheUser = $this->InstallerCheck->getWebSrvUser();
		if (empty($apacheUser)) {
			$this->out('<error>' . __d('cake_installer', 'Error on getting the username of the web server process') . '</error>');

			return false;
		}

		$tmpFile = TMP . 'installer' . DS . uniqid('cron_');
		$tmpCrurrFile = TMP . 'installer' . DS . uniqid('cron_');
		$bkpFile = TMP . 'installer' . DS . 'crontab.bkp';
		$output = [];
		$exitCode = -1;
		$cmd = 'crontab -u ' . $apacheUser . ' -l >' . $tmpFile . ' 2>/dev/null';
		exec($cmd, $output, $exitCode);
		if (($exitCode !== 0) && !$this->_createCrontabFile($tmpFile)) {
			$this->out('<error>' . __d('cake_installer', 'Error on getting crontab for user \'%s\'', $apacheUser) . '</error>');

			return false;
		}

		$tailOpt = [
			'ellipsis' => '...',
			'exact' => true,
			'html' => false
		];
		$messages = [];
		$oFileCurr = new File($tmpFile, true);
		if (!$oFileCurr->copy($tmpCrurrFile)) {
			$this->out('<error>' . __d('cake_installer', 'Error on creation copy of current crontab.') . '</error>');
			$oFileCurr->delete();

			return false;
		}
		$oFileBkp = new File($tmpCrurrFile, false);

		$needUpdate = false;
		$cronFile = $oFileCurr->read();
		foreach ($cronjobsList as $cmd => $time) {
			if (empty($cmd) || empty($time)) {
				continue;
			}

			$jobState = false;
			if (!empty($cronFile)) {
				if (preg_match('/^[^#]+' . preg_quote($cmd, '/') . '$/m', $cronFile)) {
					$jobState = true;
				} else {
					$jobState = $oFileCurr->append($time . ' ' . $cmd . "\n");
					$needUpdate = true;
				}
			} else {
				$jobState = $oFileCurr->append($time . ' ' . $cmd . "\n");
				$needUpdate = true;
			}
			if ($jobState) {
				$state = '<success>' . __d('cake_installer', 'Ok') . '</success>';
			} else {
				$state = '<error>' . __d('cake_installer', 'Bad') . '</error>';
				$result = false;
			}

			$state = '[' . $state . ']';
			$message = ' * ' . CakeText::tail($cmd, $this->maxWidth - 12, $tailOpt);
			$messages[] = $this->state->getState($message, $state, $this->maxWidth - 1);
		}
		if (!$oFileCurr->close()) {
			$result = false;
			$messages[] = '<error>' . __d('cake_installer', 'Error on closing cron file.') . '</error>';
		} elseif ($needUpdate) {
			$output = [];
			$exitCode = -1;
			$cmd = 'crontab -u ' . $apacheUser . ' ' . $tmpFile . ' 2>/dev/null';
			exec($cmd, $output, $exitCode);
			if ($exitCode !== 0) {
				$result = false;
				$messages[] = '<error>' . __d('cake_installer', 'Error on updating crontab.') . '</error>';
			} else {
				if (!$oFileBkp->copy($bkpFile, true)) {
					$this->out('<error>' . __d('cake_installer', 'Error on creation copy of previous crontab.') . '</error>');
					$result = false;
				}
			}
		}
		$oFileCurr->delete();
		$oFileBkp->delete();

		if (empty($messages)) {
			$messages[] = '<info>' . __d('cake_installer', 'List of cron jobs is empty') . '</info>';
		} elseif (!$needUpdate) {
			$messages[] = '<info>' . __d('cake_installer', 'Crontab update is not required.') . '</info>';
		}

		$this->out($messages, 1);
		$this->hr();
		if ($result) {
			$this->out('<success>' . __d('cake_installer', 'Creating cron jobs completed successfully.') . '</success>');
		} else {
			$this->out('<error>' . __d('cake_installer', 'Creating cron jobs unsuccessfully.') . '</error>');
		}

		return $result;
	}
1322608
public static function inList($check, array $list, $caseInsensitive = false)
    {
        if ($caseInsensitive) {
            $list = array_map('mb_strtolower', $list);
            $check = mb_strtolower($check);
        } else {
            $list = array_map('strval', $list);
        }

        return in_array((string)$check, $list, true);
    }
858246
public function checked($checked = [])
    {
        if ($checked instanceof Arrayable) {
            $checked = $checked->toArray();
        }

        $this->checked = array_merge($this->checked, $checked);

        return $this;
    }
416262
protected static function getFilename($check)
    {
        if ($check instanceof UploadedFileInterface) {
            try {
                // Uploaded files throw exceptions on upload errors.
                return $check->getStream()->getMetadata('uri');
            } catch (RuntimeException $e) {
                return false;
            }
        }
        if (is_array($check) && isset($check['tmp_name'])) {
            return $check['tmp_name'];
        }

        if (is_string($check)) {
            return $check;
        }

        return false;
    }
856400
public static function time($check)
    {
        if ($check instanceof DateTimeInterface) {
            return true;
        }
        if (is_array($check)) {
            $check = static::_getDateString($check);
        }

        return static::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
    }
989861
protected function module($check = null) {
        $module = Util::camelToHyphen($this->view->getModule());
        return $check ? ($check == $module) : $module;
    }
825819
public function clear($check)
    {
        if ($check) {
            return true;
        }

        $keys = $this->_Memcached->getAllKeys();
        if ($keys === false) {
            return false;
        }

        foreach ($keys as $key) {
            if (strpos($key, $this->_config['prefix']) === 0) {
                $this->_Memcached->delete($key);
            }
        }

        return true;
    }
582981
public function setChecked(array $checked)
    {
        foreach ($this->checkboxes as $checkbox) {
            /* @var $checkbox Checkbox */
            $checkbox->setChecked(in_array($checkbox->getName(), $checked));
        }

        return $this;
    }
839100
public function check(array $config): bool
    {
        // we dont use the phpversion function because that adds more data to the number (Like: -1+ubuntu16.04)
        // that conflicts with the semver check
        return Semver::satisfies(
            PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION,
            $this->getRequiredPhpConstraint()
        );
    }
311634
def luhn_check(number)
      multiplications = []

      number.split(//).each_with_index do |digit, i|
        if i % 2 == 0
          multiplications << digit.to_i * 2
        else
          multiplications << digit.to_i
        end
      end

      sum = 0
      multiplications.each do |num|
        num.to_s.each_byte do |character|
          sum += character.chr.to_i
        end
      end

      if sum % 10 == 0
        control_digit = 0
      else
        control_digit = (sum / 10 + 1) * 10 - sum
      end

      control_digit.to_s
    end
60014
public function clear($check)
    {
        if (!$this->_init) {
            return false;
        }
        $this->_File = null;

        $threshold = $now = false;
        if ($check) {
            $now = time();
            $threshold = $now - $this->_config['duration'];
        }

        $this->_clearDirectory($this->_config['path'], $now, $threshold);

        $directory = new RecursiveDirectoryIterator(
            $this->_config['path'],
            \FilesystemIterator::SKIP_DOTS
        );
        $contents = new RecursiveIteratorIterator(
            $directory,
            RecursiveIteratorIterator::SELF_FIRST
        );
        $cleared = [];
        foreach ($contents as $path) {
            if ($path->isFile()) {
                continue;
            }

            $path = $path->getRealPath() . DIRECTORY_SEPARATOR;
            if (!in_array($path, $cleared)) {
                $this->_clearDirectory($path, $now, $threshold);
                $cleared[] = $path;
            }
        }

        return true;
    }
573335
public function checkIntegrity($check=true,$schema='')
	{
		$enable=$check ? 'CHECK' : 'NOCHECK';
		if(!isset($this->_normalTables[$schema]))
			$this->_normalTables[$schema]=$this->findTableNames($schema,false);
		$db=$this->getDbConnection();
		foreach($this->_normalTables[$schema] as $tableName)
		{
			$tableName=$this->quoteTableName($tableName);
			$db->createCommand("ALTER TABLE $tableName $enable CONSTRAINT ALL")->execute();
		}
	}
632399
public static function all($items, callable $check)
    {
        foreach ($items as $item) {
            if (!call_user_func($check, $item)) {
                return false;
            }
        }

        // Return false if array is empty
        return isset($item) ? true : false;
    }