Generator that yields values between 1-100, represents the percentage of progress when cloning a book in its entirety

@since 5.7.0
@throws \Exception
@return \Generator
768091
public function cloneBookGenerator() : \Generator {

		yield 1 => __( 'Looking up the source book', 'pressbooks' );
		if ( ! $this->setupSource() ) {
			throw new \Exception( ! empty( $_SESSION['pb_errors'][0] ) ? $_SESSION['pb_errors'][0] : __( 'Failed to setup source', 'pressbooks' ) );
		}

		// Create Book
		yield 10 => __( 'Creating the target book', 'pressbooks' );
		$this->targetBookId = $this->createBook();
		$this->targetBookUrl = get_blogaddress_by_id( $this->targetBookId );

		switch_to_blog( $this->targetBookId );
		wp_defer_term_counting( true );

		// Pre-processor
		$this->clonePreProcess();

		// Clone Metadata
		yield 20 => __( 'Cloning metadata', 'pressbooks' );
		$this->clonedItems['metadata'][] = $this->cloneMetadata();

		// Clone Taxonomy Terms
		$y = new PercentageYield( 30, 40, count( $this->sourceBookTerms ) );
		$this->targetBookTerms = $this->getBookTerms( $this->targetBookUrl );
		foreach ( $this->sourceBookTerms as $term ) {
			yield from $y->tick( __( 'Cloning contributors and licenses', 'pressbooks' ) );
			$new_term = $this->cloneTerm( $term['id'] );
			if ( $new_term ) {
				$this->termMap[ $term['id'] ] = $new_term;
				$this->clonedItems['terms'][] = $new_term;
			}
		}

		// Clone Front Matter
		$y = new PercentageYield( 40, 50, count( $this->sourceBookStructure['front-matter'] ) );
		foreach ( $this->sourceBookStructure['front-matter'] as $frontmatter ) {
			yield from $y->tick( __( 'Cloning front matter', 'pressbooks' ) );
			$new_frontmatter = $this->cloneFrontMatter( $frontmatter['id'] );
			if ( $new_frontmatter !== false ) {
				$this->clonedItems['front-matter'][] = $new_frontmatter;
			}
		}

		// Clone Parts and chapters
		$ticks = 0;
		foreach ( $this->sourceBookStructure['parts'] as $key => $part ) {
			$ticks += 1 + count( $this->sourceBookStructure['parts'][ $key ]['chapters'] );
		}
		$y = new PercentageYield( 50, 80, $ticks );
		foreach ( $this->sourceBookStructure['parts'] as $key => $part ) {
			yield from $y->tick( __( 'Cloning parts and chapters', 'pressbooks' ) );
			$new_part = $this->clonePart( $part['id'] );
			if ( $new_part !== false ) {
				$this->clonedItems['parts'][] = $new_part;
				foreach ( $this->sourceBookStructure['parts'][ $key ]['chapters'] as $chapter ) {
					yield from $y->tick( __( 'Cloning parts and chapters', 'pressbooks' ) );
					$new_chapter = $this->cloneChapter( $chapter['id'], $new_part );
					if ( $new_chapter !== false ) {
						$this->clonedItems['chapters'][] = $new_chapter;
					}
				}
			}
		}

		// Clone Back Matter
		$y = new PercentageYield( 80, 90, count( $this->sourceBookStructure['back-matter'] ) );
		foreach ( $this->sourceBookStructure['back-matter'] as $backmatter ) {
			yield from $y->tick( __( 'Cloning back matter', 'pressbooks' ) );
			$new_backmatter = $this->cloneBackMatter( $backmatter['id'] );
			if ( $new_backmatter !== false ) {
				$this->clonedItems['back-matter'][] = $new_backmatter;
			}
		}

		// Clone Glossary
		$y = new PercentageYield( 90, 100, count( $this->sourceBookGlossary ) );
		foreach ( $this->sourceBookGlossary as $glossary ) {
			yield from $y->tick( __( 'Cloning glossary terms' ) );
			$new_glossary = $this->cloneGlossary( $glossary['id'] );
			if ( $new_glossary !== false ) {
				$this->clonedItems['glossary'][] = $new_glossary;
			}
		}

		// Post-processor
		$this->clonePostProcess();

		wp_defer_term_counting( false ); // Flush
		restore_current_blog();

		yield 100 => __( 'Finishing up', 'pressbooks' );
	}
592749
public function join(): \Generator
    {
        if (null === $this->delayed) {
            throw new StatusError('The process has not been started.');
        }

        $this->poll->listen();

        try {
            return yield $this->delayed;
        } finally {
            $this->stdout->close();
            $this->stderr->close();
        }
    }
1001755
public function generated(): ?GeneratorVerifier
    {
        $cardinality = $this->cardinality;

        if ($result = $this->checkGenerated()) {
            return $result;
        }

        return $this->assertionRecorder->createFailure(
            $this->assertionRenderer->renderGenerated($this->spy, $cardinality)
        );
    }
1157336
public function generate()
    {
        if (is_null($this->publicKey)) {
            throw new \Exception('Public Key has not been set');
        }

        $compressedValue = $this->publicKey;

        if (empty($compressedValue)) {
            throw new \Exception('The Public Key needs to be generated.');
        }

        $step1 = Util::sha256(Util::binConv($compressedValue), true);

        $step2 = Util::ripe160($step1);

        $step3 = sprintf(
            '%s%s%s',
            self::SIN_VERSION,
            self::SIN_TYPE,
            $step2
        );

        $step4 = Util::twoSha256(Util::binConv($step3), true);

        $step5 = substr(bin2hex($step4), 0, 8);

        $step6 = $step3.$step5;

        $this->value = Base58::encode($step6);

        return $this;
    }
522153
public function values(): self
    {
        return static::create(
            function () {
                /** @noinspection YieldFromCanBeUsedInspection */
                foreach ($this->getGenerator() as $value) {
                    yield $value;
                }
            },
            $this->iteratorClass,
            false
        );
    }
180334
public function getMutationScoreIndicator(): float
    {
        $detectionRateAll = 0;
        $defeatedTotal = $this->killedCount + $this->timedOutCount + $this->errorCount;

        if ($this->totalMutantsCount) {
            $detectionRateAll = floor(100 * $defeatedTotal / $this->totalMutantsCount);
        }

        return $detectionRateAll;
    }
1308143
public function sizes(): Generator
    {
        for ($s = clone $this->min; $s->compare($this->max) < 1; $s = $s->add($this->step)) {
            yield $s;
        }
    }
1184437
protected function generateWord()
	{
		$wordFile=dirname(__FILE__).'/words.txt';
		$words=preg_split("/[\s,]+/",file_get_contents($wordFile));
		do
		{
			$i=rand(0,count($words)-1);
			$word=$words[$i];
		} while(strlen($word)<5 || !ctype_alpha($word));
		return strtoupper($word);
	}
1101037
private function doAcquire(): \Generator {
        // Try to create the lock file. If the file already exists, someone else
        // has the lock, so set an asynchronous timer and try again.
        while (($handle = @\fopen($this->fileName, 'x')) === false) {
            yield new Delayed(self::LATENCY_TIMEOUT);
        }

        // Return a lock object that can be used to release the lock on the mutex.
        $lock = new Lock(0, function () {
            $this->release();
        });

        \fclose($handle);

        return $lock;
    }
509942
public function getIterator(): Generator
    {
        foreach ($this->packageRoots as $root) {
            $rootPaths = [];
            $packages = [];

            // Search each namespace we've been provided.
            foreach ($this->namespaces as $namespace) {

                // Try to find the root within this namespace.
                // If we find it, aggregate the paths to scan for packages later.
                $package = $namespace->findNamespace($root);
                if ($package) {
                    $rootPaths = array_merge($rootPaths, $package->getPaths());
                }

                // If the namespace itself is actually a package within the root we're searching for,
                // aggregate it's path to scan as a package for later.
                if ($namespace->getParentId() === $root) {
                    if (!array_key_exists($namespace->getId(), $packages)) {
                        $packages[$namespace->getId()] = [];
                    }
                    $packages[$namespace->getId()] = array_merge(
                        $packages[$namespace->getId()],
                        $namespace->getPaths()
                    );
                }
            }

            // If we found any root paths, scan them for packages.
            if ($rootPaths) {
                $namespace = new Psr4Namespace($root, ...$rootPaths);
                yield from $this->scanRoot($namespace);
            }

            // If we found any package paths, scan them.
            foreach ($packages as $id => $paths) {
                $namespace = new Psr4Namespace($id, ...$paths);
                yield from $this->loadPackage($namespace);
            }
        }
    }
834099
protected function get()
    {
        $a = 0;
        $b = 1;
        $to = $this->getMaxLimit();
        while (0 < $to) {
            yield $a;

            list($a, $b) = [$b, $a + $b];
            --$to;
        }
    }
252239
public function getIterator() : \Generator
    {
        for ($current = $this->start; $current->isBeforeOrEqualTo($this->end); $current = $current->plusMonths(1)) {
            yield $current;
        }
    }
193933
private function fqcn(): \Generator
    {
        foreach ($this->paths() as $root => $path) {
            $x = substr($path, strlen($root) + 1, -4);

            $fqcn = implode('', [$this->namespace, '\\', str_replace('/', '\\', $x)]);

            yield $fqcn => $fqcn;
        }
    }
148456
public static function generate()
    {
        if (version_compare(PHP_VERSION, '7.0.0', '<')) {
            return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
                mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
                mt_rand(0, 0x0fff) | 0x4000,
                mt_rand(0, 0x3fff) | 0x8000,
                mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
            );
        } else {
            $uuid = bin2hex(random_bytes(18));
            $uuid[8] = $uuid[13] = $uuid[18] = $uuid[23] = '-';
            $uuid[14] = '4';

            return $uuid;
        }
    }
132125
public function shutdown(): \Generator
    {
        if (!$this->isRunning()) {
            throw new StatusError('The pool is not running.');
        }

        $this->running = false;

        $shutdowns = [];

        foreach ($this->workers as $worker) {
            if ($worker->isRunning()) {
                $shutdowns[] = new Coroutine($worker->shutdown());
            }
        }

        return yield Awaitable\reduce($shutdowns, function ($carry, $value) {
            return $carry ?: $value;
        }, 0);
    }
450514
public function generate(int $count = 100): Generator
    {
        for ($i = 0; $i < $count; $i++) {
            yield (bool)mt_rand(0, 1);
        }
    }
202173
public function progress()
    {
        try {
            $progress = $this->sdk()->jobs->progress($this->model->job_id);
            if ($progress->state == 'finished') {
                return 100;
            }

            return $progress->progress;
        } catch (\Exception $e) {
            return 0;
        }
    }