Get Endomondo workout from old API

@param $source array
@return Workout
173511
static function parseWorkout($source)
    {
        $workout = new Workout();

        $workout
            ->setSource($source)
            ->setTypeId($source['sport'])
            ->setDuration($source['duration'])
            ->setStart(new \DateTime($source['start_time']))
            ->setMapPrivacy($source['privacy_map'])
            ->setWorkoutPrivacy($source['privacy_workout']);

        if ($source['id']) {
            $workout->setId($source['id']);
        }

        if ($source['calories']) {
            $workout->setCalories($source['calories']);
        }

        if ($source['distance']) {
            $workout->setDistance($source['distance']);
        }

        if (isset($source['points'])) {
            $points = [];
            foreach ($source['points'] as $point) {
                $points[] = OldApiParser::parsePoint($point);
            }
            $workout->setPoints($points);
        }

        if (isset($source['heart_rate_avg'])) {
            $workout->setAvgHeartRate($source['heart_rate_avg']);
        }

        if (isset($source['heart_rate_max'])) {
            $workout->setMaxHeartRate($source['heart_rate_max']);
        }

        if (isset($source['notes'])) {
            $workout->setNotes($source['notes']);
        }

        return $workout;
    }
614651
public function for(Source $source): string
    {
        if (isset($this->presentationModels[$source])) {
            return (string)$this->presentationModels[$source];
        }

        return PresentationModel::class;
    }
1314244
public static function fromArray( $source )
	{
		try
		{
			$classname = get_called_class();

			if ( ! class_exists( $classname ) )
			{
				\XBRL_Log::getInstance()->err( "The class '$classname' does not exist" );
				return null;
			}

			$instance = new $classname();

			if ( ! $instance instanceof Resource )
			{
				\XBRL_Log::getInstance()->err( "The class instance being created MUST inherit from 'XBRL\\Formulas\\Resources\\Resources'" );
				return null;
			}

			$has = get_object_vars( $instance );
			foreach ( $has as $name => $oldValue )
			{
	        	if ( ! isset( $source[ $name ] ) ) continue;
	        	$instance->$name = $source[ $name ];
			}

			return $instance;
		}
		catch( \Exception $ex )
		{
			return null;
		}
	}
420541
public function get_file_reference($source) {
        if ($source && $this->has_moodle_files()) {
            $params = @json_decode(base64_decode($source), true);
            if (!is_array($params) || empty($params['contextid'])) {
                throw new repository_exception('invalidparams', 'repository');
            }
            $params = array(
                'component' => empty($params['component']) ? ''   : clean_param($params['component'], PARAM_COMPONENT),
                'filearea'  => empty($params['filearea'])  ? ''   : clean_param($params['filearea'], PARAM_AREA),
                'itemid'    => empty($params['itemid'])    ? 0    : clean_param($params['itemid'], PARAM_INT),
                'filename'  => empty($params['filename'])  ? null : clean_param($params['filename'], PARAM_FILE),
                'filepath'  => empty($params['filepath'])  ? null : clean_param($params['filepath'], PARAM_PATH),
                'contextid' => clean_param($params['contextid'], PARAM_INT)
            );
            // Check if context exists.
            if (!context::instance_by_id($params['contextid'], IGNORE_MISSING)) {
                throw new repository_exception('invalidparams', 'repository');
            }
            return file_storage::pack_reference($params);
        }
        return $source;
    }
75598
protected function getEndpoint($method)
    {
        $endpoint = "jobs";
        $jobId = $this->getArgument("id");
        if (!is_null($jobId)) {
            $endpoint .= "/$jobId";
            $this->delArgument("id");
        }
        $page = $this->getArgument("page");
        $this->delArgument("page");
        if (!is_null($page)) {
            $endpoint .= "?page=$page";
        }
        if (!is_null($this->getArgument("accept_any_file"))) {
            $endpoint .= "/result";
        }
        return $endpoint;
    }
185030
protected function castStream($source): StreamInterface
    {
        if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) {
            $source = $source->getStream();
        }

        if ($source instanceof StreamInterface) {
            //This step is important to prevent user errors
            $source->rewind();

            return $source;
        }

        if (is_resource($source)) {
            return stream_for($source);
        }

        if (empty($source)) {
            //Guzzle?
            return stream_for('');
        }

        if ($this->isFilename($source)) {
            //Must never pass user string in here, use Stream
            return stream_for(fopen($source, 'rb'));
        }

        //We do not allow source names in a string form
        throw new BucketException(
            "Source must be a valid resource, stream or filename, invalid value given"
        );
    }
302445
public function fromJSON( $source )
	{
		$types = json_decode( $source, true );

		if ( json_last_error() !== JSON_ERROR_NONE )
		{
			$message = sprintf( "Error parsing JSON %s", XBRL::json_last_error_msg() );
			XBRL_Log::getInstance()->err( $message );
			return false;
		}

		return $this->fromArray( $types );
	}
814257
public function getDataSource(string  $source) : Source
	{
		switch ($source) {
			case 'form':
			case 'forms':
				return $this
					->getDataSources()
					->getFormsDataSource();
				break;
			case 'entry':
			case 'entries':
				return $this
					->getDataSources()
					->getEntryDataSource();
				break;
			case 'entryValue':
			case 'entryValues':
				return $this
					->getDataSources()
					->getEntryValuesDataSource();
		}
	}
143808
protected function getAsync(array $endpoints, $params = [])
    {
        /** @var Promise[] $promises */
        $promises = array_map(function (Endpoint $endpoint) use ($params) {
            $isCached = $this->client->getCache() && $this->client->getCache()->getItem(KeyGenerator::fromEndpoint($endpoint))->isHit();
            
            if ($endpoint->countsTowardsLimit() && !$isCached) {
                try {
                    $this->client->getMethodRateLimiter()->hit($endpoint);
                    $this->client->getAppRateLimiter()->hit($endpoint);
                } catch (RateLimitReachedException $e) {
                    return new RejectedPromise($e);
                }
            }

            return $this->client->getHttpClient()
                ->sendAsyncRequest($this->buildRequest($endpoint, $params))
                ->then(function (ResponseInterface $response) use ($endpoint) {
                    return $response
                        ->withHeader('X-Endpoint', $endpoint->getName())
                        ->withHeader('X-Request', $endpoint->getUrl())
                        ->withHeader('X-Region', $endpoint->getRegion()->getName());
                });
        }, is_array($endpoints) ? $endpoints : [$endpoints]);

        // Wait for multiple requests to complete, even if some fail
        if (count($promises) > 1) {
            $results = \GuzzleHttp\Promise\settle($promises)->wait();

            return BatchResult::fromSettledPromises($results);
        }

        // Resolve a single request
        $result = $promises[0]->wait();

        if (! $result instanceof ResponseInterface) {
            throw $result;
        }

        return Result::fromPsr7($result);
    }
694411
public function load($source)
    {
        if (isset($this->_messages[$source])) {
            return $this->_messages[$source];
        } else {
            $filename_cordillera = CORDILLERA_DIR.'languages'.DS.$this->language.DS.$source.'.php';
            $filename_app = CORDILLERA_APP_DIR.'languages'.DS.$this->language.DS.$source.'.php';

            $this->_messages[$source] = is_file($filename_app) ?
                require_once $filename_app : (is_file($filename_cordillera) ? require_once $filename_cordillera : []);
        }

        return $this->_messages[$source];
    }
443183
protected function getNextFollowingTransition($source, $sourceId, $hydrationMode)
    {
        $transition = $this->transitionManager->findOneBySource($source, $sourceId);

        if ($transition !== null) {
            $transitionResult = $this->createTransitionResult(
                $transition->getDestination(),
                $transition->getDestinationId(),
                $hydrationMode
            );

            if (!$transitionResult) {
                return null;
            }

            $transitionResult->setId($transition->getId());
            $transitionResult->setTransition($transition);

            return $transitionResult;
        }

        return null;
    }
944940
public static function source($source)
    {
        $ins         = new static();
        $ins->source = $source;

        //inherit cid from datafilter
        if ($ins->source instanceof \Zofe\Rapyd\DataFilter\DataFilter) {
            $ins->cid = $ins->source->cid;
        }
        //generate new component id
        else {
            $ins->cid = $ins->getIdentifier();
        }

        return $ins;
    }
862253
public function importSourceNode($source)
    {
        $DOMDocument = new self();
        $DOMDocument->loadHTML($source);

        $this->metaNodes->import($DOMDocument->metaNodes);
        $this->headScriptNodes->import($DOMDocument->headScriptNodes);
        $this->bodyScriptNodes->import($DOMDocument->bodyScriptNodes);
        $this->linkNodes->import($DOMDocument->linkNodes);
        $this->styleContent->import($DOMDocument->styleContent);
        $this->headScriptContent->import($DOMDocument->headScriptContent);
        $this->bodyScriptContent->import($DOMDocument->bodyScriptContent);

        $bodyElement = $DOMDocument->getElementsByTagName('body')->item(0);

        if ($bodyElement->firstChild instanceof Dom\Element) {
            return $bodyElement->firstChild;
        } elseif ($bodyElement->firstChild instanceof \DOMText) {
            foreach ($bodyElement->childNodes as $childNode) {
                if ($childNode instanceof Dom\Element) {
                    return $childNode->cloneNode(true);
                    break;
                }
            }
        }

        return $bodyElement;
    }
625155
protected function sourceToStream($source): StreamInterface
    {
        if (is_string($source)) {
            $source = Psr7\try_fopen($source, 'r+');
        }

        return Psr7\stream_for($source);
    }
240351
public function getTableColumnsForSourceAction($source, $table)
    {
        $columns = $this->externalUserGroupSyncManager->getColumnNamesForTable($source, $table);

        return new JsonResponse($columns);
    }
458695
public function findAndUpdate($source)
    {
        /** @var Redirect|null $redirect */
        $redirect = $this->om->getRepository($this->class)->findOneBy(array('source' => $source));

        if (null === $redirect) {
            return null;
        }

        $redirect->increaseCount();
        $redirect->updateLastAccessed();
        $this->om->flush();

        return $redirect;
    }
786270
private function getDeletedFields(Source $source)
    {
        $fields = array();
        $fields += array(
            'undelete' => array(
                'type' => 'button',
                'value' => $this->t('undelete'),
                'ajax' => array(
                    'service' => 'entry_deletestatus_set',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => API::Entry_Delete,
                ),
            ),
            'send' => array(
                'type' => 'button',
                'value' => $this->t('send_again'),
                'ajax' => array(
                    'service' => 'invoice_add',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => 1,
                ),
            ),
        );
        return $fields;
    }