Class: Dev::Php

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/php.rb,
lib/firespring_dev_commands/php/audit.rb

Overview

Class containing methods related to php applicatio

Defined Under Namespace

Classes: Audit, Config

Constant Summary collapse

DEFAULT_PATH =

The default path of the application inside the container

'/usr/src/app'.freeze
DEFAULT_PACKAGE_FILE =

The default name of the php package file

'composer.json'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_path: nil, local_path: nil, package_file: nil, coverage: nil) ⇒ Php

Returns a new instance of Php.



36
37
38
39
40
41
42
# File 'lib/firespring_dev_commands/php.rb', line 36

def initialize(container_path: nil, local_path: nil, package_file: nil, coverage: nil)
  @container_path = container_path || self.class.config.container_path
  @local_path = local_path || self.class.config.local_path
  @package_file = package_file || self.class.config.package_file
  @coverage = coverage || Dev::Coverage::None.new
  raise 'coverage must be an instance of the base class' unless @coverage.is_a?(Dev::Coverage::Base)
end

Instance Attribute Details

#container_pathObject

Returns the value of attribute container_path.



34
35
36
# File 'lib/firespring_dev_commands/php.rb', line 34

def container_path
  @container_path
end

#coverageObject

Returns the value of attribute coverage.



34
35
36
# File 'lib/firespring_dev_commands/php.rb', line 34

def coverage
  @coverage
end

#local_pathObject

Returns the value of attribute local_path.



34
35
36
# File 'lib/firespring_dev_commands/php.rb', line 34

def local_path
  @local_path
end

#package_fileObject

Returns the value of attribute package_file.



34
35
36
# File 'lib/firespring_dev_commands/php.rb', line 34

def package_file
  @package_file
end

Class Method Details

.config {|@config| ... } ⇒ Object Also known as: configure

Instantiates a new top level config object if one hasn’t already been created Yields that config object to any given block Returns the resulting config object

Yields:



24
25
26
27
28
# File 'lib/firespring_dev_commands/php.rb', line 24

def config
  @config ||= Config.new
  yield(@config) if block_given?
  @config
end

Instance Method Details

#audit_commandObject

Build the command which can be use to perform a security audit report



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/firespring_dev_commands/php.rb', line 50

def audit_command
  audit = base_command
  audit << 'audit'
  audit << '--no-interaction'
  audit << '--no-cache'
  audit << '--format' << 'json'
  audit.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  audit << '2>&1' << '||' << 'true'

  # Run the command as part of a shell script
  ['sh', '-c', audit.join(' ')]
end

#audit_fix_commandObject

Build the command to fix any security vulnerabilities that were found



64
65
66
# File 'lib/firespring_dev_commands/php.rb', line 64

def audit_fix_command
  raise 'not implemented'
end

#base_commandObject

The base npm command that is the starting point for all subsequent commands



45
46
47
# File 'lib/firespring_dev_commands/php.rb', line 45

def base_command
  ['composer', '--working-dir', container_path]
end

#check_test_coverage(application:) ⇒ Object

Run the check to ensure code coverage meets the desired threshold



102
103
104
# File 'lib/firespring_dev_commands/php.rb', line 102

def check_test_coverage(application:)
  coverage.check(application:)
end

#install_commandObject

Build the php install command



69
70
71
72
73
74
# File 'lib/firespring_dev_commands/php.rb', line 69

def install_command
  install = base_command
  install << 'install'
  install.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  install
end

#lint_commandObject

Build the php lint command



77
78
79
80
81
82
# File 'lib/firespring_dev_commands/php.rb', line 77

def lint_command
  lint = base_command
  lint << 'run' << 'lint' << '--'
  lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint
end

#lint_fix_commandObject

Build the php lint fix command



85
86
87
88
89
90
# File 'lib/firespring_dev_commands/php.rb', line 85

def lint_fix_command
  lint_fix = base_command
  lint_fix << 'run' << 'lint-fix' << '--'
  lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  lint_fix
end

#test_commandObject

Build the php test command



93
94
95
96
97
98
99
# File 'lib/firespring_dev_commands/php.rb', line 93

def test_command
  test = base_command
  test << 'run' << 'test' << '--'
  test.concat(coverage.php_options) if coverage
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
  test
end