diff --git a/README.md b/README.md index aff9109c..8e7de488 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ The best way to start is to [open a new issue](https://github.com/kevinpapst/kim In case you want to contribute, but you wouldn't know how, here are some suggestions: -- Spread the word: More user means more people testing and contributing to Kimai - which in turn means better stability and more and better features. Please vote for Kimai on platforms lie Slant, Product Hunt, Softpedia or AlternativeTo, you can tweet about it, share it on LinkedIn, reddit or any of your favorite social media platforms. Every little bit helps! +- Spread the word: More user means more people testing and contributing to Kimai - which in turn means better stability and more and better features. Please vote for Kimai on platforms like Slant, Product Hunt, Softpedia or AlternativeTo, you can tweet about it, share it on LinkedIn, reddit or any of your favorite social media platforms. Every bit helps! - Answer questions: You know the answer to another user's problem? Share your knowledge! - Make a feature request: Something can be done better? Something essential missing? Let us know! - Report bugs diff --git a/src/Configuration/StringAccessibleConfigTrait.php b/src/Configuration/StringAccessibleConfigTrait.php index 161edd65..8ea77a22 100644 --- a/src/Configuration/StringAccessibleConfigTrait.php +++ b/src/Configuration/StringAccessibleConfigTrait.php @@ -54,39 +54,13 @@ trait StringAccessibleConfigTrait return; } - // this foreach should be replaced by a better piece of code, - // especially the pointers could be a problem in the future foreach ($this->getConfigurations($this->repository) as $configuration) { - $temp = explode('.', $configuration->getName()); - $this->setConfiguration($temp, $configuration->getValue()); + $this->set($configuration->getName(), $configuration->getValue()); } $this->initialized = true; } - private function setConfiguration(array $keys, ?string $value): void - { - $array = &$this->settings; - if ($keys[0] === $this->getPrefix()) { - $keys = \array_slice($keys, 1); - } - foreach ($keys as $key2) { - if (!\array_key_exists($key2, $array)) { - $array[$key2] = $value; - continue; - } - if (\is_array($array[$key2])) { - $array = &$array[$key2]; - } elseif (\is_bool($array[$key2])) { - $array[$key2] = (bool) $value; - } elseif (\is_int($array[$key2])) { - $array[$key2] = (int) $value; - } else { - $array[$key2] = $value; - } - } - } - /** * @return string */ @@ -186,7 +160,7 @@ trait StringAccessibleConfigTrait */ public function offsetSet($offset, $value) { - $this->setConfiguration(explode('.', $offset), $value); + $this->set($offset, $value); } /** @@ -197,4 +171,43 @@ trait StringAccessibleConfigTrait { throw new \BadMethodCallException('SystemBundleConfiguration does not support offsetUnset()'); } + + /** + * Set an array item to a given value using "dot" notation. + * + * If no key is given to the method, the entire array will be replaced. + * + * @see https://github.com/divineomega/array_undot + * @param string $key + * @param mixed $value + * + * @return array + */ + private function set(string $key, $value): array + { + $array = &$this->settings; + $keys = explode('.', $key); + while (\count($keys) > 1) { + $key = array_shift($keys); + if (!isset($array[$key]) || !\is_array($array[$key])) { + $array[$key] = []; + } + + $array = &$array[$key]; + } + + $k = array_shift($keys); + + if (\array_key_exists($k, $array)) { + if (\is_bool($array[$k])) { + $value = (bool) $value; + } elseif (\is_int($array[$k])) { + $value = (int) $value; + } + } + + $array[$k] = $value; + + return $array; + } } diff --git a/src/Constants.php b/src/Constants.php index facd7212..39ef1c29 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -17,11 +17,11 @@ class Constants /** * The current release version */ - public const VERSION = '1.19.1'; + public const VERSION = '1.19.2'; /** * The current release: major * 10000 + minor * 100 + patch */ - public const VERSION_ID = 11901; + public const VERSION_ID = 11902; /** * The current release status, either "stable" or "dev" */ diff --git a/src/DataFixtures/TimesheetFixtures.php b/src/DataFixtures/TimesheetFixtures.php index dff2e8e4..7d983510 100644 --- a/src/DataFixtures/TimesheetFixtures.php +++ b/src/DataFixtures/TimesheetFixtures.php @@ -38,7 +38,6 @@ class TimesheetFixtures extends Fixture implements FixtureGroupInterface public const MIN_TIMESHEETS_PER_USER = 50; public const MAX_TIMESHEETS_PER_USER = 500; public const MAX_TIMESHEETS_TOTAL = 200; - public const MAX_RUNNING_TIMESHEETS_PER_USER = 1; public const MIN_MINUTES_PER_ENTRY = 15; public const MAX_MINUTES_PER_ENTRY = 840; // 14h public const MAX_DESCRIPTION_LENGTH = 200; @@ -87,7 +86,7 @@ class TimesheetFixtures extends Fixture implements FixtureGroupInterface if ($i % 3 === 0) { $description = $faker->realText($faker->numberBetween(10, self::MAX_DESCRIPTION_LENGTH)); } elseif ($i % 7 === 0) { - $description = substr($faker->text, 0, self::MAX_DESCRIPTION_LENGTH); + $description = substr($faker->text(), 0, self::MAX_DESCRIPTION_LENGTH); } $entry = $this->createTimesheetEntry( @@ -109,8 +108,7 @@ class TimesheetFixtures extends Fixture implements FixtureGroupInterface } // create active recordings for test user - $activeEntries = rand(0, self::MAX_RUNNING_TIMESHEETS_PER_USER); - for ($i = 0; $i < $activeEntries; $i++) { + if (rand(0, 10) >= 5) { $entry = $this->createTimesheetEntry( $user, $activities[array_rand($activities)], diff --git a/src/Form/Type/ProjectType.php b/src/Form/Type/ProjectType.php index a3f54639..552a333c 100644 --- a/src/Form/Type/ProjectType.php +++ b/src/Form/Type/ProjectType.php @@ -82,7 +82,7 @@ class ProjectType extends AbstractType $name = $this->getPattern(); $name = str_replace(self::PATTERN_NAME, $project->getName(), $name); $name = str_replace(self::PATTERN_COMMENT, $project->getComment() ?? '', $name); - $name = str_replace(self::PATTERN_ORDERNUMBER, $project->getOrderNumber(), $name); + $name = str_replace(self::PATTERN_ORDERNUMBER, $project->getOrderNumber() ?? '', $name); $name = str_replace(self::PATTERN_START, $start, $name); $name = str_replace(self::PATTERN_END, $end, $name);