Check if we can load the file and return the properties.

@param phingFile $propertiesFile Properties file
@param string    $propertyType   Type of file

@throws BuildException

@return array
423557
protected function checkLoadProperties($propertiesFile, $propertyType)
    {

        if ($propertiesFile->exists() && $propertiesFile->isDirectory()) {
            $message = $propertyType." is a directory!";
            $this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
            return;
        }

        if ($propertiesFile->exists() && !$propertiesFile->canRead()) {
            $message = "Can not read from the specified ".$propertyType."!";
            $this->_haltOnErrorAction(null, $message, Project::MSG_ERR);
            return;
        }

        $fileParserFactory = new FileParserFactory();
        $fileParser        = $fileParserFactory->createParser($propertiesFile->getFileExtension());
        $properties        = new Properties(null, $fileParser);

        $properties->load($propertiesFile);

        return $properties->getProperties();

    }
723393
private function checkForMissingPropertyType(
        StatementsSource $source,
        PhpParser\Node\Stmt\Property $stmt,
        Context $context
    ) {
        $comment = $stmt->getDocComment();

        if (!$comment || !$comment->getText()) {
            $fq_class_name = $source->getFQCLN();
            $property_name = $stmt->props[0]->name->name;

            $codebase = $this->getCodebase();

            $property_id = $fq_class_name . '::$' . $property_name;

            $declaring_property_class = $codebase->properties->getDeclaringClassForProperty(
                $property_id,
                true
            );

            if (!$declaring_property_class) {
                throw new \UnexpectedValueException(
                    'Cannot get declaring class for ' . $property_id
                );
            }

            $fq_class_name = $declaring_property_class;

            // gets inherited property type
            $class_property_type = $codebase->properties->getPropertyType($property_id, false, $source, $context);

            if ($class_property_type) {
                return;
            }

            $message = 'Property ' . $property_id . ' does not have a declared type';

            $class_storage = $codebase->classlike_storage_provider->get($fq_class_name);

            $property_storage = $class_storage->properties[$property_name];

            if ($property_storage->suggested_type && !$property_storage->suggested_type->isNull()) {
                $message .= ' - consider ' . str_replace(
                    ['<mixed, mixed>', '<empty, empty>'],
                    '',
                    (string)$property_storage->suggested_type
                );
            }

            if (IssueBuffer::accepts(
                new MissingPropertyType(
                    $message,
                    new CodeLocation($source, $stmt->props[0]->name)
                ),
                $this->source->getSuppressedIssues()
            )) {
                // fall through
            }
        }
    }
528303
private function takeProperties(File $baseFile): void
    {
        $baseProps = get_object_vars($baseFile);

        array_walk($baseProps, function ($value, $key) {
            $this->$key = $value;
        });
    }
570040
protected LinkedHashMap<Pattern, String> load(File propertyFile) {
    LinkedHashMap<Pattern, String> result = new LinkedHashMap<Pattern, String>();
    BufferedReader reader = null;
    try {
      reader =
          new BufferedReader(new InputStreamReader(new FileInputStream(propertyFile), "UTF-8"));
      String line;
      while ((line = reader.readLine()) != null) {
        if (line.length() == 0) {
          continue;
        }
        char firstChar = line.charAt(0);
        if (firstChar == '#' || firstChar == '!') {
          continue;
        }
        int pos = line.indexOf('=');
        if (pos < 0) {
          continue;
        }
        String key = line.substring(0, pos);
        String value = line.substring(pos + 1, line.length());
        int pos2 = line.indexOf('@');
        if (pos2 == 0) {
          key = key.substring(1);
        } else if (pos2 > 0) {
          key = Pattern.quote(key.substring(0, pos2)) + key.substring(pos2);
        }
        result.put(Pattern.compile(key), value);
      }
    } catch (IOException e) {
      throw new GenException(Message.DOMAGEN9001, e, e);
    } finally {
      IOUtil.close(reader);
    }
    return result;
  }
370690
protected function getDefaultValueForProperty(NodeType $nodeType, $propertyName)
    {
        $defaultValues = $nodeType->getDefaultValuesForProperties();
        if (!isset($defaultValues[$propertyName])) {
            return null;
        }

        return $defaultValues[$propertyName];
    }
79466
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
    {
        if (($propertyType === null) || (!in_array($propertyType, array(self::PROPERTY_TYPE_INTEGER,
                                                                        self::PROPERTY_TYPE_FLOAT,
                                                                        self::PROPERTY_TYPE_STRING,
                                                                        self::PROPERTY_TYPE_DATE,
                                                                        self::PROPERTY_TYPE_BOOLEAN)))) {
            if ($propertyValue === null) {
                $propertyType = self::PROPERTY_TYPE_STRING;
            } elseif (is_float($propertyValue)) {
                $propertyType = self::PROPERTY_TYPE_FLOAT;
            } elseif (is_int($propertyValue)) {
                $propertyType = self::PROPERTY_TYPE_INTEGER;
            } elseif (is_bool($propertyValue)) {
                $propertyType = self::PROPERTY_TYPE_BOOLEAN;
            } else {
                $propertyType = self::PROPERTY_TYPE_STRING;
            }
        }

        $this->customProperties[$propertyName] = array(
            'value' => $propertyValue,
            'type' => $propertyType
        );
        return $this;
    }
440716
private function getProperties(UploadedFile $uploadedFile)
    {
        $mimeType = $uploadedFile->getMimeType();
        $properties = [];

        try {
            // if the file is a video we add the duration
            if (fnmatch('video/*', $mimeType) && $this->ffprobe) {
                $properties['duration'] = $this->ffprobe->format($uploadedFile->getPathname())->get('duration');

                // Dimensions
                try {
                    $dimensions = $this->ffprobe->streams($uploadedFile->getPathname())->videos()->first()->getDimensions();
                    $properties['width'] = $dimensions->getWidth();
                    $properties['height'] = $dimensions->getHeight();
                } catch (\InvalidArgumentException $e) {
                    // Exception is thrown if the video stream could not be obtained
                } catch (\RuntimeException $e) {
                    // Exception is thrown if the dimension could not be extracted
                }
            }
        } catch (ExecutableNotFoundException $e) {
            // Exception is thrown if ffmpeg is not installed -> video properties are not set
        }

        return $properties;
    }
263558
private static Properties getPropertiesFile() {
        try {

            // We use the class loader to load the properties file.
            // This compatible with unix and windows.
            final InputStream stream = TangoFactory.class.getClassLoader().getResourceAsStream(
                    FACTORY_PROPERTIES);
            final Properties properties = new Properties();

            // We read the data in the properties file.
            if (stream != null) {
                // We need to use a Buffered Input Stream to load the datas
                final BufferedInputStream bufStream = new BufferedInputStream(stream);
                properties.clear();
                properties.load(bufStream);
            }
            return properties;
        } catch (final Exception e) {
            e.printStackTrace();
            return null;
        }
    }
25135
public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) {
		$typeDeclaration = \TYPO3\Flow\Utility\TypeHandling::parseType($targetType);
		if ($typeDeclaration['elementType'] !== NULL) {
			return $typeDeclaration['elementType'];
		}

		$configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue('TYPO3\Flow\Property\TypeConverter\ObjectConverter', self::CONFIGURATION_TARGET_TYPE);
		if ($configuredTargetType !== NULL) {
			return $configuredTargetType;
		}

		$methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct');
		if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) {
			return $methodParameters[$propertyName]['type'];
		} elseif ($this->reflectionService->hasMethod($targetType, ObjectAccess::buildSetterMethodName($propertyName))) {
			$methodParameters = $this->reflectionService->getMethodParameters($targetType, ObjectAccess::buildSetterMethodName($propertyName));
			$methodParameter = current($methodParameters);
			if (isset($methodParameter['type'])) {
				return $methodParameter['type'];
			}
		} else {
			$targetPropertyNames = $this->reflectionService->getClassPropertyNames($targetType);
			if (in_array($propertyName, $targetPropertyNames)) {
				$values = $this->reflectionService->getPropertyTagValues($targetType, $propertyName, 'var');
				if (count($values) > 0) {
					return current($values);
				}
			}
		}

		return 'string';
	}
639713
public function checkReadFile($readFile)
    {
        if (null === $readFile) {
            return false;
        }
        if (!file_exists($readFile)) {
            $msg = "$readFile does not exist.";
            if ($this->haltonerror) {
                throw new BuildException($msg);
            }
            $this->log($msg, Project::MSG_ERR);
            return false;
        }
        if (!is_readable($readFile)) {
            $msg = "$readFile is not readable.";
            if ($this->haltonerror) {
                throw new BuildException($msg);
            }
            $this->log($msg, Project::MSG_ERR);
            return false;
        }
        $this->ini->read($readFile);
        $this->log("Read from $readFile");
        return true;
    }
1061433
private function executeCommand($inputFile, $outputFile)
    {
        // Prevent over-writing existing file.
        if ($inputFile == $outputFile) {
            throw new BuildException('Input file and output file are the same!');
        }

        $output = [];
        $return = null;

        $fullCommand = $this->executable;

        if (strlen($this->flags) > 0) {
            $fullCommand .= " {$this->flags}";
        }

        $fullCommand .= " {$inputFile} {$outputFile}";

        exec($fullCommand, $output, $return);

        return [$return, $output];
    }
518238
private Map<String, String> getOptionsFromPropertiesFile(String newPropertiesFile) throws MojoExecutionException {

        this.getLog().debug("Using search path at: " + this.basedir.getAbsolutePath());
        this.resourceManager.addSearchPath(FileResourceLoader.ID, this.basedir.getAbsolutePath());

        Properties properties = new Properties();
        try {
            properties.load(this.resourceManager.getResourceAsInputStream(newPropertiesFile));
        } catch (ResourceNotFoundException e) {
            getLog().debug("Property file [" + newPropertiesFile + "] cannot be found", e);
            return new HashMap<>();
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot read config file [" + newPropertiesFile + "]", e);
        }

        final Map<String, String> map = new HashMap<>();
        for (final String name : properties.stringPropertyNames()) {
            map.put(name, properties.getProperty(name));
        }
        return map;
    }
686708
Properties loadCostProperties(Path cachePath, String machineType) {
    Properties prop = new Properties();
    InputStream inp = null;
    try {
      inp = new FileInputStream(cachePath.toString());
      prop.load(inp);
      return prop;
    } catch (FileNotFoundException fnf) {
      LOG.error("cost properties does not exist, using default values");
      return null;
    } catch (IOException e) {
      LOG.error("error loading properties, using default values");
      return null;
    } finally {
      if (inp != null) {
        try {
          inp.close();
        } catch (IOException ignore) {
          // do nothing
        }
      }
    }
  }
483310
protected function getPropertyData(PropertyMetadata $property, $propertyValue)
    {
        return $this->createProperty(
            $property->getName(),
            $this->exportManager->export($property->getType(), $propertyValue),
            $this->exportManager->getOptions($property->getType(), $this->format),
            $property->getType()
        );
    }
160129
protected function getPropertyType($type)
    {
        $propertyType = ucfirst($type);
        if (isset(self::$_propertyTypes[$type])) {
            $propertyType = self::$_propertyTypes[$type];
        }

        return $propertyType;
    }
894804
protected function generateProperty($propertyName, array $data, $directory, array $dataTypes)
    {
        $property = $this->getPropertyClassName($propertyName);

        $class = new PhpClass();
        $class
            ->setQualifiedName('SecIT\\SchemaOrg\\Mapping\\Property\\'.$property)
            ->setParentClassName('AbstractProperty')
            ->setDescription($property.' class.'."\n\n".'@method '.$property.' setValue($value)')
            ->setMethod(PhpMethod::create('getSchemaUrl')
                ->setDescription('Get schema URL.')
                ->setType('string')
                ->setBody('return \''.$data['url'].'\';')
            )
        ;

        if ($this->backwardCompatibility && !$this->php7ClassNames) {
            $this->php7ClassNames = true;
            $deprecatedMessage = 'This class is deprecated and will be removed in release 3.4. Use SecIT\\SchemaOrg\\Mapping\\Property\\'.$this->getPropertyClassName($propertyName).' instead.';
            $this->php7ClassNames = false;
            $class->setDescription($class->getDescription()."\n\n".'@deprecated '.$deprecatedMessage);
        }

        $instanceCheckConditions = [];
        foreach ($data['ranges'] as $range) {
            if (isset($dataTypes[$range])) {
                $class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\DataType');
                $instanceCheckConditions[] = '$value instanceof DataType\\'.$this->getDataTypeClassName($range);
            } else {
                $class->addUseStatement('SecIT\\SchemaOrg\\Mapping\\Type');
                $instanceCheckConditions[] = '$value instanceof Type\\'.$this->getTypeClassName($range);
            }
        }

        // if no conditions than always return true
        if (!$instanceCheckConditions) {
            $instanceCheckConditions[] = 'true';
        }

        $class
            ->setMethod(PhpMethod::create('isValueValid')
                ->setDescription('Check is value valid.')
                ->addParameter(PhpParameter::create('value')
                    ->setType('string')
                )
                ->setType('bool')
                ->setBody('return '.implode(' || ', $instanceCheckConditions).';')
            )
        ;

        $generator = new CodeGenerator();
        $code = $generator->generate($class);

        file_put_contents($directory.$property.'.php', "<?php\n\n".$code);
    }
1153940
public function checkWriteFile($writeFile)
    {
        if (file_exists($writeFile) && !is_writable($writeFile)) {
            $msg = "$writeFile is not writable";
            if ($this->haltonerror) {
                throw new BuildException($msg);
            }
            $this->log($msg, Project::MSG_ERR);
            return false;
        }
        return true;
    }